how to pass object by reference in android to make changes in orignal object?
friends,
i have code
DalCategories selected_object= new DalCategories();
for (DalCategories cat : DalCategories.EditPostCategory)
{
if(cat.getCategory_Id().equals(root_id))
{
selected_object = cat;
// add to list
if(selected_object.getSub_Category() != null)
{
for (DalCategories t : selected_object.getSub_Category())
{
if(t.getSub_Category() != null)
{
// MakeChangesInThisObject(t.getSub_Category());
adapter.addSection(t.getTitle(), new EfficientAdapter(this,t.getSub_Category(),selected_object.getSub_Category().get(0).getSub_Category()));
}
}
}开发者_如何学Python
// add to list
break;
}
}
DalCategories.EditPostCategory has three levels i want to change third level object values and want this change should be done to DalCategories.EditPostCategory by reference and using MakeChangesInThisObject
any one guide me how to achieve this?
Before you try and learn Android learn a bit of java. All objects are passed around by reference. It would be crazy if each time you passed a reference the entire thing was cloned/copied especially when it is not necessary because the class is immutable.
Think what would happen if you created a byte array with 500000 bytes. If it got copied each time a method was called with it as a parameter, your cpu would be wasted copying this array lots of times without actually doing anything.
精彩评论