Community
Participate
Working Groups
The Java compiler that comes with Eclipse does not let me call clone() method on any object that do implement both the Cloneable interface and the method. By the way, the class I am referring to is java.util.Vector.
clone() is declared as public in all classes and interfaces involved.
Could you please provide a small piece of code that would show the problem? Thanks.
import java.util.Vector; public class A { public A() { Vector v = new Vector(); Vector q = (Vector) v.clone(); // compiler complains about clone() not being visible } }
What build are you using? I tried with M8 and it compiles without a problem.
Cannot reproduce in 3.0 builds.
Note that if you had written: Object v = new Vector(); Vector q = (Vector) v.clone(); then an error would have been expected, as Object.clone() is protected.
It would be true if I used Object.clone(). But I am using Vector.clone() and that, I believe (according to documentation) is public.
Terribly sorry. I didn't notice your previous comment. So, if I download the latest 1.9, it should work, right?
Which Eclipse build are you using ? I don't remember fixing this any recently...
Set a = new HashSet(); Collection c = (Collection) a.clone(); That is the code. You were right - the type whose clone() I used (Set) didn't define it at all. So, the clone() was taken from Object. As soon as I casted "a" to the concrete type, it worked. Thanks for help and sorry for taking your time.