I have a very basic doubt in Java.
Here is a code I have written. From a method in class A in package A, I try to instantiate an object of class b of a different package and call its method, to which I pass a list.
parseObjectList = new ArrayList<ParseObject>();
pullAllService.pullAllData(queryType,parseObjectList);
and in the function I do some manipulation:
public void pullAllData(String queryType,List<ParseObject> parseObjectList)
{
ParseQuery<ParseObject> query = null;
List<ParseObject> parseObjects = parseObjectList;
if(queryType.equals("a"))
{
query = new ParseQuery<ParseObject>("a");
}
else if(queryType.equals("b"))
{
query = new ParseQuery<ParseObject>("b");
}
try {
parseObjects = query.find(); //I get the list
/* final List<ParseObject> finalParseObjectList = parseObjectList;
curActivity.runOnUiThread(new Runnable() {
public void run() {
ToastMessageHelper.displayLongToast(curActivity, "Objects found : ");
for (int i = 0; i < finalParseObjectList.size(); i++) {
ToastMessageHelper.displayLongToast(curActivity, finalParseObjectList.get(i).get("Name").toString());
System.out.println();
}
}
});
*/
} catch (ParseException e) {
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
after which if I try to print the list in class A's method. I get an empty list.
But if I do this,
parseObjectList = new ArrayList<ParseObject>();
parseObjectList = pullAllService.pullAllData(queryType,parseObjectList);
and make it return the list from pullAllData() (by changing the return type and returning the list) , I get the list with the expected data.
I thought that just by passing the parseObjectList into the function, the passed parameter would behave as a reference and automatically be assigned the intended data. What's wrong here?