Can you explain me such behavior of this code:
class Test{
public List<String> change(List<String> s){
List<String> tmp = s;
tmp.add("test");
return tmp;
}
public Integer change(Integer s){
Integer tmp = s;
tmp++;
return tmp;
}
}
public class Main {
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
Integer i = new Integer(10);
Test t = new Test();
System.out.println(l);
t.change(l);
System.out.println(l);
System.out.println(i);
t.change(i);
System.out.println(i);
}
}
And the result is:
[]
[test]
10
10
Why my list is changed even if inside change() method I create tmp variable and ascribe to it passed argument and my Integer is not change in the same situation?