On Sunday 19 October 2008 17:39:12 Bryan Duxbury wrote: > I'm not sure this would get you all the way to the hashability you're > looking for. Maybe it's just the terminology I'm thinking in is > different, but what you want is a run-time flag to set immutability, > not a compile-time immutable field. You'd do something like > myObj.setImmutable(), and it would make all the setters throw > exceptions, as well as have the sense to trickle down to all the > mutable subordinate objects. This approach wouldn't work in all > generators (default Java, for instance, since there ARE no setters, > just fields), but should work for most.
No, what I want is real compile-time immutability, not just calling some method to set it. It means that, in the Java case, classes would be declared as final, no public fields, no setters, etc. However, the problem is that, as you pointed out, the default Java generator exposes fields, since the beans generator is optional. Also, I would like to note that it would be a type modifier, and it would enforce immutability only if you add it to Thrift structures. Cheers.
