M
Matteo
I need to use clone() on generics but I don't know how to do.
If I write, for example,
Vector<String> v1 = new Vector<String>();
Vector<String> v2 = new Vector<String>();
v1.add("a");
v2 = v1.clone();
it gives me the error
xyz: incompatible types
found : java.lang.Object
required: java.util.Vector<java.lang.String>
v2 = v1.clone();
^
if I cast to generics doing
Vector<String> v1 = new Vector<String>();
Vector<String> v2 = new Vector<String>();
v1.add("a");
v2 = (Vector<String>)v1.clone();
it gives me the warning:
Util.java:252: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Vector<java.lang.String>
v2 = (Vector<String>)v1.clone();
^
1 warning
Well, I can understand this because clone() returns an Object.
But how I can use clone without warnings??
Thank you vey much,
Matteo
If I write, for example,
Vector<String> v1 = new Vector<String>();
Vector<String> v2 = new Vector<String>();
v1.add("a");
v2 = v1.clone();
it gives me the error
xyz: incompatible types
found : java.lang.Object
required: java.util.Vector<java.lang.String>
v2 = v1.clone();
^
if I cast to generics doing
Vector<String> v1 = new Vector<String>();
Vector<String> v2 = new Vector<String>();
v1.add("a");
v2 = (Vector<String>)v1.clone();
it gives me the warning:
Util.java:252: warning: [unchecked] unchecked cast
found : java.lang.Object
required: java.util.Vector<java.lang.String>
v2 = (Vector<String>)v1.clone();
^
1 warning
Well, I can understand this because clone() returns an Object.
But how I can use clone without warnings??
Thank you vey much,
Matteo