digitalmars.D - final class member variable NOT LIKE JAVA!
- Garett Bass (19/19) Jan 01 2006 Expecting final to work as it does in Java, I wrote the following:
- Frank Benoit (5/5) Jan 01 2006 See the in digitalmars.D.learn ng.
- Chris Miller (3/22) Jan 01 2006 Use const instead.
Expecting final to work as it does in Java, I wrote the following: class Bar { int i = 2; } class Foo { final Bar bar; this(Bar bar) { this.bar = bar; } } You can imagine my surprise when I was allowed to do the following: int main(char[][] args) { Foo foo = new Foo; foo.bar = new Bar; // final should not allow this! return 0; } I worked around it by creating a property method that only permits 'get' access to bar, but it was so much more elegant when it was just final Bar bar. Oh well, Garett
Jan 01 2006
See the in digitalmars.D.learn ng. There was this "final variable" discussion just yesterday. Frank -- D goes real-time: http://www.drealtime.com
Jan 01 2006
On Sun, 01 Jan 2006 21:06:57 -0500, Garett Bass <garettbass studiotekne.com> wrote:Expecting final to work as it does in Java, I wrote the following: class Bar { int i = 2; } class Foo { final Bar bar; this(Bar bar) { this.bar = bar; } } You can imagine my surprise when I was allowed to do the following: int main(char[][] args) { Foo foo = new Foo; foo.bar = new Bar; // final should not allow this! return 0; } I worked around it by creating a property method that only permits 'get' access to bar, but it was so much more elegant when it was just final Bar bar. Oh well, GarettUse const instead.
Jan 01 2006