Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

immutable object that holds Objects

Thread view: 
Mize-ze - 01 Apr 2007 11:54 GMT
I have an immutable object that needs to hold (Among the rest) two
"Object" objects

for all the mutable objects my object holds I create a "defensive
copy" but what can I do with the "Object" objects? can I somehow clone
them so they can't be changed from outside the object?

BTW: I can't know what is the type of the Object before run-time...
(that's way it is an "Object")

Thanks.
Tom Hawtin - 01 Apr 2007 13:28 GMT
> I have an immutable object that needs to hold (Among the rest) two
> "Object" objects
[quoted text clipped - 5 lines]
> BTW: I can't know what is the type of the Object before run-time...
> (that's way it is an "Object")

No.

I suggest using a wrapper interface that can be copied, and a wrapper
implementation for each type of object that you want your immutable to hold.

Tom hawtin
Hendrik Maryns - 02 Apr 2007 11:09 GMT
Tom Hawtin schreef:
>> I have an immutable object that needs to hold (Among the rest) two
>> "Object" objects
[quoted text clipped - 11 lines]
> implementation for each type of object that you want your immutable to
> hold.

Indeed, for inspiration, have a look at Collections.unmodifiableX(X)
where X is Set Collection or Map.  Or maybe that is what you need?

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.