Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Cloning and Interfaces
|
Posted: Nov 5, 2004 10:53 AM
|
|
Hmm... Yes, you are correct. It looks like if you remove() an item in a sublist, the original is unaffected, but if you clear() the sublist, that portion of the original will be cleared.
Perhaps they ought to introduce this to replace Cloneable:
interface Clonable
{
Object clone();
}
In the next release, killing two birds (the misspelling and the missing method) with one cliche. I guess for a little more backward compatibility it might be:
interface Clonable extends Cloneable
{
Object clone();
}
I think the intention of the Cloneable interface is to behave only as a tag (like a C# attribute) for reflection to determine whether an object can be cloned. However, you need to implement the method clone() for this purpose, so why not have it in the interface? I think maybe it was explained in Josh Bloch's Effective Java, but I forget the rationale and I don't have the book with me.
So it looks like maybe you are stuck with the clunky instanceof hack. Of course, if you get passed an instance of some new implementation of List that you weren't expecting, you'll be hosed.
|
|