Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7740757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:51:42+00:00 2026-06-01T08:51:42+00:00

I have an Object X which contains a list of Objects X. I do

  • 0

I have an Object X which contains a list of Objects X.
I do a loop on the list and pass an Object X from the list to another activity through an Intent.

In the other activity, I modify this Object X and then return this modified Object X.

When I get back the Object X in my first activity, I can see it’s been modified, this point is ok.

But the root Object X (the one containing the list of Objects X and from which comes from the modified Object X), shouldn’t it be modified as well as I passed a reference to the intent ?

If not, how can I manage to have it modified as the root depth of Objects X inside other Objects X can be deep ?

(tell me in I’m not clear enough).

Thanks for your help.
I have an activity with send and Object X through another activity

My object to be more precise (don’t pay attention of the fact that it is Serializable and not Parcelable, I’ll fix this later):

public class CategoryBean implements Externalizable, Cloneable {
    public static final boolean ACTIVE = true;
    public static final boolean INACTIVE = false;

    public static final int VALIDATED = 1;
    public static final int NON_OBSERVED = 2;
    public static final int IN_PROGRESS = 3;
    public static final int PARTIEL = 4;

    private String perimetre;
    private CategoryBean parentCategory;
    private List<CategoryBean> categoryList = new ArrayList<CategoryBean>();
    protected String title;
    /**
     * Category validée ou non
     */
    protected int state;
    /**
     * Category active ou inactive
     */
    protected boolean activated = ACTIVE;

    // public CategoryBean(Parcel in) {
    // this.parentCategory = in.readParcelable(CategoryBean.class.getClassLoader());
    // this.categoryList = Arrays.asList(in.readParcelableArray(CategoryBean.class.getClassLoader()));
    // this.title = in.readString();
    // }

    /**
     * @return the parentCategory
     */
    public CategoryBean getParentCategory() {
        return parentCategory;
    }

    /**
     * @return the perimetre
     */
    public String getPerimetre() {
        return perimetre;
    }

    /**
     * @param perimetre
     *            the perimetre to set
     */
    public void setPerimetre(String perimetre) {
        this.perimetre = perimetre;
    }

    /**
     * @param parentCategory
     *            the parentCategory to set
     */
    public void setParentCategory(CategoryBean parentCategory) {
        this.parentCategory = parentCategory;
    }

    /**
     * @return the category
     */
    public List<CategoryBean> getCategoryList() {
        return categoryList;
    }

    /**
     * @param category
     *            the category to set
     */
    public void setCategoryList(List<CategoryBean> categoryList) {
        this.categoryList = categoryList;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title
     *            the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the state
     */
    public int getState() {
        return state;
    }

    /**
     * @param state
     *            the state to set
     */
    public void setState(int state) {
        this.state = state;
    }

    /**
     * @return the activated
     */
    public boolean isActivated() {
        return activated;
    }

    /**
     * @param activated
     *            the activated to set
     */
    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    @Override
    public int hashCode() {
        return parentCategory.hashCode() + categoryList.hashCode() + title.hashCode();
    }

    @SuppressWarnings("unchecked")
    @Override
    public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException {
        setPerimetre((String) input.readObject());
        setParentCategory((CategoryBean) input.readObject());
        setCategoryList((List<CategoryBean>) input.readObject());
        setTitle((String) input.readObject());
        setState((Integer) input.readObject());
        setActivated((Boolean) input.readObject());
    }

    @Override
    public void writeExternal(ObjectOutput output) throws IOException {
        output.writeObject(getPerimetre());
        output.writeObject(getParentCategory());
        output.writeObject(getCategoryList());
        output.writeObject(getTitle());
        output.writeObject(getState());
        output.writeObject(isActivated());
    }

    @Override
    public CategoryBean clone() throws CloneNotSupportedException {
        try {
            CategoryBean clone = (CategoryBean) super.clone();
            clone.setPerimetre(clone.getPerimetre());
            clone.setParentCategory(clone.getParentCategory());
            clone.setCategoryList(clone.getCategoryList());
            clone.setTitle(clone.getTitle());
            clone.setState(clone.getState());
            clone.setActivated(clone.isActivated());
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("( CategoryBean -> ");
        sb.append(" perimetre : ");
        sb.append(getPerimetre());
        sb.append(" parentCategory : ");
        sb.append(getParentCategory() != null ? getParentCategory().getTitle() : null);
        sb.append(" categoryList : ");
        sb.append(getCategoryList());
        sb.append(" title : ");
        sb.append(getTitle());
        sb.append(" state : ");
        sb.append(getState());
        sb.append(" activated : ");
        sb.append(isActivated());
        sb.append(" )");
        return sb.toString();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:51:43+00:00Added an answer on June 1, 2026 at 8:51 am

    In general i wouldn’t recommend to do modifications by reference even if its possible in Java. It has several drawbacks that will become clear later in development stage when you have thousand of lines of code and a few other developers working on the same project and everyone is wondering why the heck the list items get modified magically and WHERE 🙂

    I would suggest you simply store the modified object back into the list replacing it. All you have to do is keep track of the index.

    Use the set method of the List interface:

    set(int index, Object element) 
          Replaces the element at the specified position in this list with the specified element.
    

    EDIT:
    That would also be a cleaner approach in terms of low coupling and modularity. So one activity doesn’t rely on another and can be reused for a specific task.

    To answer your exact question: I guess Android does clone the item or due to serialization of the item it is copied/newly created and not passed by reference, because of the reasons mentioned above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this huge domain object(say parent) which contains other domain objects. It takes
I have a List which contains a list of objects and I want to
Currently I have an object which I receive from a server, this contains two
We have an object, A, which contains another object, B. We have Hibernate calling
Assuming I have object_list list which contains objects. I want to check if my
I have two generic list objects, in which one contains ids and ordering, and
Problem: I have a document class which contains a list of objects. These objects
I have a list of Nodes which I loop through: for (int i =
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
I have an object(A) which has a list composed of objects (B). The objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.