Cloneable and Immutable
Florian Weimer
fweimer at bfk.de
Thu Aug 20 00:24:39 PDT 2009
* Max Wang:
> Also, if it's a final class, is it better to simply return this?
No, in this case, it's better not to implement clone() at all. One
thing that's pretty clear in the Object#clone() contract is that it's
a fresh object, that is, that x.clone() != x. Even with immutable
objects, the difference is observable with synchronization and
identity-based hashing.
--
Florian Weimer <fweimer at bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99
More information about the jdk7-dev
mailing list