I have a function which returns a reference to an object. Why cannot I assign this returned reference to point to another object? The reference being returned by the function is not final , hence I should be allowed to change it's value to point to another object.
class TestClass3 {
public TestClass3 hello() {
TestClass3 t = new TestClass3();
return t;
}
}
class TestClass1 {
public static void main(String[] args) {
TestClass3 obj = new TestClass3();
// The below line of code gives an error
obj.hello() = null;
}
}
I expect that the reference returned by calling the hello() method should be assigned null value.