H
here
They've been talking about it for years. Should be spelled Clonable.
Will it ever happen? Just curious.
Will it ever happen? Just curious.
[email protected] said:They've been talking about it for years.
Should be spelled Clonable.
Will it ever happen?
They've been talking about it for years. Should be spelled Clonable.
Will it ever happen? Just curious.
The problem with Cloneable is that it doesn't export any public methods,
it's just a "mix-in" type. Cloneable would be better if it guaranteed
that the implementing class supported a public clone() method.
Lew said:Since 'clone()' is a method of the primordial 'Object' type, having
it
as part of the 'Cloneable' interface would not do much. You would
always at least trivially implement the interface, and could not
prevent failure to adhere to a deep-copy semantic. Having the
primordial 'clone()' check for that marker interface and thrown an
Exception in the face of its absence is an evil hack, though.
I guess the reason to have it in 'Object' and not implemented solely
by implementors of 'Cloneable' is to provide the primordial
implementation from the very top. Otherwise a class that did
implement 'Cloneable' would not be able to do so, because none of
its
ancestor type information would clone.
Mike said:It would have made more sense for
1. Cloneable to define public clone(), and
2. the protected primordial method to have a name other than clone()
I think that gives he same ability to enable or disable cloning as you
like, and isn't as difficult to explain .
Mark said:Just to clarify, the following is at least syntactically correct, even
though it will in fact throw an error. But that's only because the
illustration I use doesn't actually implement Cloneable, just my own
version of it.
interface myCloneable extends Cloneable
{
Object clone();
}
class Test implements myCloneable
{
@Override
public Object clone()
{
Object copy = null;
try {
copy = super.clone();
}
catch( CloneNotSupportedException ex ) {
System.out.println( "oops" );
}
return copy;
}
}
Lew said:But it should work if you make your version extend the java.lang
version:
> Mark Space wrote:
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.