JDK 8 code review request for 7140820 Add covariant overrides to Collections clone methods
Ulf Zibis
Ulf.Zibis at gmx.de
Mon Jan 30 13:16:40 UTC 2012
Am 30.01.2012 13:19, schrieb Tom Hawtin:
> A better solution to the unchecked casts from clone, is not to clone. Using a constructor gets rid
> of the problem, and ensures you aren't using some funky (potentially malicious) subclass.
>
> - return (Hashtable<String, java.lang.Object>)_env.clone();
> + return new Hashtable<>(_env);
Isn't cloning faster than normal instantiation?
I can imagine, that behind the scenes cloning mainly only needs to duplicate the binary footprint of
an object.
-Ulf
More information about the core-libs-dev
mailing list