immutable object that holds Objects

M

Mize-ze

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.
 
T

Tom Hawtin

Mize-ze said:
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")

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
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tom Hawtin schreef:
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.

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFGENbYe+7xMGD3itQRApgtAJ9DHRPT+78TKgm6bOE1PCrVA8MB1QCdFgVb
Qx6tCRbcsB/IreFQVntxnTE=
=W9xQ
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top