RefVsVal.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.ArrayList; public class RefVsVal{ public static void valueCopy(int i){ i++; } public static void refCopy(ArrayList<Integer> aj){ aj.add(20); } public static void main(String[] args){ int j = 42; valueCopy(j); System.out.println(j); ArrayList<Integer> ai = new ArrayList<>(); ai.add(19); refCopy(ai); System.out.println(ai); } } |