Is there a difference between the following two :
ArrayList list = getData();
public ArrayList getData(){
return otherList;
}
and
ArrayList list = someOtherArrayList;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case directly address of someOtherArrayList is assigned to list.
In this case, address of list returned is copied into temporary variable and later temporary variable to list. Here address copied in temporary variable because : When function returns, all its data on stack is deallocated/deleted, so otherList object reference is also deleted. But before that it is reference/address is copied into temporary variable. When address from temporary variable is copied in list variable. It is also deleted.