[java] how to cast after clone()?
Vector a= new Vector();
Vector b= a.clone(); //1.
Vector b=(Vector) a.clone();//2.
Vector b=(Vector) a. clone(); //3
i have tried all the three ways of casting, but all of them will produce either an error or a warning. Can anyone suggest how to do casting in this case? thanks a lot in advance!
我试了,第三个可以啊
[atp@gateway ~]$ cat aaa.java
import java.util.Vector;
public class aaa
{
public static void main (String [] s)
{
Vector<String> a = new Vector<String>();
a.add("hi");
Vector<String> b = (Vector<String>)a.clone();
System.out.println(b);
}
}
[atp@gateway ~]$ javac aaa.java
Note: aaa.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
[atp@gateway ~]$ java aaa
[hi]
[atp@gateway ~]$
import java.util.Vector;
public class aaa
{
public static void main (String [] s)
{
Vector<String> a = new Vector<String>();
a.add("hi");
Vector<String> b = (Vector<String>)a.clone();
System.out.println(b);
}
}
[atp@gateway ~]$ javac aaa.java
Note: aaa.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
[atp@gateway ~]$ java aaa
[hi]
[atp@gateway ~]$