[concurrency-interest] Joda-Time immutability

Mark Thornton mthornton at optrak.com
Mon Jun 20 11:06:13 EDT 2011


On 20/06/11 15:03, Stephen Colebourne wrote:
> The "reflection can set final fields" comment was directed at
> serialization, but has actually provided a reasonably acceptable
> solution (thanks Mark).
>
> Basically, I've made the fields final, and changed the setters to use
> reflection (breaking the final restriction). Since 99% of use cases
> are immutable, this will only impact the mutable users (a little bit
> slower), and they should really move to the immutable classes
> anyway...
Unfortunately I suspect that this approach doesn't meet the rules 
associated with using reflection to modify final fields. It is 
conceivable that a too clever JIT might inline a 'final' value and thus 
code might not see a change in a mutable date. However, you might get 
away with it as a transitional mechanism.

Mark



More information about the Concurrency-interest mailing list