Hello,
I wanted to ask whether there is a sane way of getting optional member variables in traits / classes. The following fails:
class foo(var x:Unit)
yields with javap -p foo.class
public class foo {
private scala.runtime.BoxedUnit x;
public void x();
public void x_$eq(scala.runtime.BoxedUnit);
public foo(scala.runtime.BoxedUnit);
}
This is bad: Not every instance needs an object reference to Unit.
General context: What I want is something like
trait myType[@specialized(Unit, Int) OptionalMetadataT]{
var payload:OptionalMetadataT
//more stuff
}
If I specialize on Int
, then I save the box. Yay!
Now, how do I specialize on singletons in a way that doesn’t store a superfluous pointer in every instance?
Or am I supposed to represent Unit as a Boolean (at least cheaper than an object reference, depending on alignment padding)? Or am I supposed to specialize by hand (lots of boilerplate)?