I am using this post as my guidance.
I want to know if I understand the following concept of pass by value in java clearly.
I have a java object and I pass it by value (so the address of the object, I guess in this case) to a function that calls a class constructor. The address of my main object is 'copied' to the constructor object. Now this constructed object and my main object are at the same address? or are pointing to the same address?
void main(){
Result result = new Result(); //empty object
Timer timer = new Timer();
timer.schedule(new UpdateResultTask(result);
result.getValue(); has some valid values. Is not empty anymore.
}
public class UpdateResultTask extends TimerTask {
private Result result;
//Constructor
public UpdateResultTask(Result result) {
this.result = result;
}
@Override
public void run() {
// the local result object gets filled here
//where response is some http response
result = response.getEntity(Result.class);
}
}
Since the change inside the local function is reflected outside in the main function, i assume that its because that at the time of construction, both the new and the old (main) object have the same address?
Do I understand it correctly? In java, pass by value for objects is just passing the copy of the objects address?