本帖最后由 彭坤 于 2012-2-11 11:42 编辑
import java.util.ArrayList;
import java.util.List;
public class TestRemoveFromList {
public static void main(String[] args) {
List<Person> personList = new ArrayList<Person>();
personList.remove(new Person("张三",18));
}
}
class Person{
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String toString() {
return "姓名:"+name + ",年龄:"+ age;
}
}
疑惑的是personList里面是空的,为什么我从里面移除一个对象没报错? |