I tried the following code,
public void test() { List<Integer> list = new ArrayList<>(); list.add(100); list.add(89); System.out.println(list); update1(list); System.out.println(list); update2(list); System.out.println(list); } public void update1(List<Integer> list) { list.remove(0); } public void update2(List<Integer> list) { list = null; }
I get the following output:
[100,89] [89] [89]
My question is why can't I assign the list as null inside the function being called?
source share