The title a little bit disappointing but I cannot figure out how to properly formulate the question. So, I show my problem on the code. For example we have:
public class Test {
public Value val;
Test(Value val){
this.val = val;
}
public static void main(String[] a){
Value val = new Value(1);
Test test1 = new Test(val);
val = new Value(2);
System.out.println(test1.val.val);
}
}
How can I change my code easily to let test1 point to the new Val (that that have the value of 2). Suppose the we need to have such references(to the actual variable and not the memory) all over the program
UPD: One of the solution I found is to make a "update" method. So I could write val.update(new Val(2))
UPD: I totally agree with the setter methods. What I want is not OOP style, but in my project I need a rapid solution even if it would not be the best. I think I found one solution(it is actually bad but faster then writing setters and getters. The solution is to create a "wrapper" class(I could name it "Reference")