Topic: 传值与传引用 求助

  Print this page

1.传值与传引用 求助 Copy to clipboard
Posted by: liner09136
Posted on: 2005-09-12 19:58

package collection;
import java.util.*;

public class ListTest {
  
  public ListTest(){
  }

public static void test(){

List list = new ArrayList();//如果有一天
list.add(new Student(2,"Tom"));
list.add(new Student(3,"Bonny"));
list.add(new Student(7,"Jack"));
list.add(new Student(4,"Steven"));
list.add(new Student(5,"Smith"));
list.add(new Student(6,"Jane"));

List linkedList = new LinkedList(list);

list.set(1,new Student(3,"NewBonny"));

System.out.println(linkedList);

}
    
  public static void main(String[] args) {
   ListTest.test();
  }
}
其中这一句 list.set(1,new Student(3,"NewBonny"));并不改变list中的值,小弟刚开始学java,理解的不是很深刻,请大家指教!

2.Re:传值与传引用 求助 [Re: liner09136] Copy to clipboard
Posted by: liner09136
Posted on: 2005-09-12 20:00

不好意思,Student 类没有写,大家应该明白

3.Re:传值与传引用 求助 [Re: liner09136] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-09-12 20:12

value of list is the reference or address of the list.

If you move some furniture into your hourse, it does not change the address of your hourse. The address of your hourse is the value of your hourse. The value of your hourse does not change!!!!

See detailed discussion here:
http://www.cjsdn.net/post/view?bid=53&id=151547&sty=1&tpg=1&age=0


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923