Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] @Immutable objects that reference each other?

ecrane

2010-03-07

Replies: Find Java Web Hosting

Author LoginPost Reply

The @Immutable annotation ensures immutability by only allowing you to modify
internal state as part of the object's constructor. The problem I'm facing
is having a set of hierarchical immutable objects that refer to each other
(basically, an immutable tree). A parent object needs to know the set of
child objects it has, and the children need to know who their parent is (as
well as who their own children might be). Once the structure has been made
(it's actually defined in application configuration files, being loaded into
object form via a custom Builder), it won't change- hence the desire to use
@Immutable. However, at the time the parent is being created, its children
might not be, making it impossible to reference them in the constructor. Is
there any way to get around this?
--
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.