标签:
今天看一同事的代码
list可以从另一个方法中获得值,看上去有点奇怪。。list在主方法中创建并传到方法中,没有赋值的,没想到的是,在子方法中赋值,这个值居然可以带到父方法中来。。
1 import java.util.*; 2 3 public class Test { 4 public static void main(String[] args) { 5 6 Person person = new Person(); 7 int a = 100; 8 int b = person.doPerson(a); 9 System.out.println(b); 10 List<String> list = new ArrayList<String>(); 11 person.doList(list); 12 System.out.println(list.size()); 13 System.out.println(list.get(0)); 14 System.out.println(list.get(1)); 15 } 16 } 17 18 class Person { 19 public int doPerson(int c) { 20 c = 50; 21 return c; 22 } 23 24 public void doList(List<String> list) { 25 list.add("hello"); 26 list.add("world"); 27 } 28 }
标签:
原文地址:http://www.cnblogs.com/stonshi/p/5399062.html