import java.util.*;
class ask2//ArrayListTest
{
public static void main(String[]args)
{
List<Student> al=new ArrayList<Student>();
al.add(new Student("lisi",17));
al.add(new Student("baby",17));
ArrayList al2=(ArrayList)al.clone();//a
}
}
class Student
{
String name ;
int age;
Student(String name ,int age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return "name="+name+","+"age="+age;
}
}
a行中为什么不正确阿?应该怎么样才能 用ArrayList类中的clone()方法呢??
class ask2//ArrayListTest
{
public static void main(String[]args)
{
List<Student> al=new ArrayList<Student>();
al.add(new Student("lisi",17));
al.add(new Student("baby",17));
ArrayList al2=(ArrayList)al.clone();//a
}
}
class Student
{
String name ;
int age;
Student(String name ,int age)
{
this.name=name;
this.age=age;
}
public String toString()
{
return "name="+name+","+"age="+age;
}
}
a行中为什么不正确阿?应该怎么样才能 用ArrayList类中的clone()方法呢??
ArrayList l = new ArrayList();
ArrayList l2 = (ArrayList)l.clone();// 代码二会出错。
ArrayList<Student> l = new ArrayList<Student>();
ArrayList<Student> l2 = (ArrayList<Student>)l.clone();
这个问题似乎在j2se5.0中新引入的bug。有待高手解答。