Threads should not be Cloneable
David Holmes
David.Holmes at oracle.com
Fri Aug 13 23:21:54 UTC 2010
tom.hawtin at oracle.com said the following on 08/14/10 00:12:
> On 13/08/2010 14:58, Chris Hegarty wrote:
>
>> protected final Object clone() throws CloneNotSupportedException {
>> throw new CloneNotSupportedException();
>
> The final can (and should, IMO) be removed.
Why? What purpose would it serve?
You can not clone the Thread. The "clone" of the subclass could only be
done via construction - so just use a constructor in the first place. As
David Schlosnagle points out any subclass of that "Cloneable" would have
to use a similar construction-based clone because super.clone() can not
return the correct type. That's a bug waiting to happen.
Why given even the smallest illusion that a Thread subclass can be cloned?
David
More information about the core-libs-dev
mailing list