Hello everyone, according to the idea, it was necessary to get a link to the object from the container method, change it by the link and make sure that it was changed, having received the link again. However, changing the value using the following method does not work.
SingleList<String> list = new SingleList<String>(); list.add("Hello"); String string = list.elementAt(0); string = string + ", world!"; System.out.println(list.elementAt(0)); But if you introduce an additional class, then everything works.
class MyStr { public String str = new String(); MyStr(String str) { this.str = str; } } SingleList<MyStr> list = new SingleList<MyStr>(); list.add(new MyStr("Hello")); MyStr string = list.elementAt(0); string.str = string.str + ", world!"; System.out.println(list.elementAt(0).str); What is the fundamental difference between 1 and 2?