Bug 62539 - Cannot call clone() for any Clonable object
Summary: Cannot call clone() for any Clonable object
Status: CLOSED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-17 15:50 EDT by Eugene CLA
Modified: 2004-05-20 00:02 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene CLA 2004-05-17 15:50:22 EDT
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.
Comment 1 Eugene CLA 2004-05-17 15:55:42 EDT
clone() is declared as public in all classes and interfaces involved.
Comment 2 Olivier Thomann CLA 2004-05-17 16:59:18 EDT
Could you please provide a small piece of code that would show the problem?
Thanks.
Comment 3 Eugene CLA 2004-05-17 17:05:59 EDT
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
    }
}
Comment 4 Olivier Thomann CLA 2004-05-17 17:32:26 EDT
What build are you using?
I tried with M8 and it compiles without a problem.
Comment 5 Philipe Mulet CLA 2004-05-18 07:45:21 EDT
Cannot reproduce in 3.0 builds.
Comment 6 Philipe Mulet CLA 2004-05-18 07:47:35 EDT
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.
Comment 7 Eugene CLA 2004-05-18 17:01:55 EDT
It would be true if I used Object.clone(). But I am using Vector.clone() and 
that, I believe (according to documentation) is public.
Comment 8 Eugene CLA 2004-05-18 17:03:42 EDT
Terribly sorry. I didn't notice your previous comment.

So, if I download the latest 1.9, it should work, right?
Comment 9 Philipe Mulet CLA 2004-05-18 17:34:33 EDT
Which Eclipse build are you using ? I don't remember fixing this any 
recently...
Comment 10 Eugene CLA 2004-05-20 00:02:47 EDT
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.