日期:2014-05-20 浏览次数:21147 次
package test;
import java.util.ArrayList;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList<Student> list=new ArrayList<Student>();
Student s=new Student();
s.setName("xiaoming");
s.setAge(20);
list.add(s);
s=list.get(0);
s.setAge(10);
System.out.println("改变后的年龄值为:"+list.get(0).getAge());
}
}
class Student{
public Student(){
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
private int age;
private String name;
}
------解决方案--------------------
代码如下
import java.util.ArrayList;
import java.util.List;
import obj.Student;
public class TestInteger {
public static void main(String[] args) {
List<Student> list = new ArrayList<Student>();
Student stu = new Student();
stu.setName("Tom");
stu.setAge(20);
list.add(stu);
stu = list.get(0);
stu.setAge(10);
System.out.println(stu.getAge());
System.out.println(list.get(0).getAge());
}
}
------解决方案--------------------
同一楼
------解决方案--------------------
应该没问题,楼主检查一下代码:)
------解决方案--------------------
我测试也是值被改变了。 10。