[ot] Scala gets a system for tracking immutability
bearophile
bearophileHUGS at lycos.com
Fri Mar 12 10:37:10 PST 2010
tim:
> So now D isn't the only OOP language with an immutability system:
This page:
http://old.nabble.com/Could-proved-immutable-classes-be-added-to-Scala--td14626792.html
Says:
>* Any class that extends an immutable class must be immutable
This seems true in D too:
immutable class Foo {
int x;
this(int xx) { this.x = xx; }
}
class Bar : Foo {
int y;
this(int xx, int yy) { super(xx); this.y = yy; }
}
void main() {
auto b = new Bar(1, 2);
b.y = 10; // Error
}
But you can omit the immutable annotation in Bar, so nowhere it's written that y too is immutable. I think this is bad, worth fixing (Bar or y have to be annotated with immutable).
Bye,
bearophile
More information about the Digitalmars-d
mailing list