java - Strange map behavior in Android application -


i have strange problem map used in application.

i have list of objects - table. each object has field map of objects of class:

public class table {      private map<integer, myobject> objectsmap = new hashmap<integer, myobject>();      public void addtomap(int i, myobject morder)     {         objectsmap.put(i, morder);     }      public myobject getobject(int poz)     {         return objectsmap.get(poz);     }  }  public class myobject {      private int info1;     private int info2;      public void setinfo(int i1, int i2)     {         this.info1 = i1;         this.info2 = i2;     }      public int[] getinfos()     {         return new int[]{this.info1, this.info2};     }  } 

then in main activity have initialization:

private list<table> tablelist = new arraylist<table>();  //...  public void inittableobject(table mytable) {     myobject newobject = new myobject();     newobject.setinfo(1,2);     mytable.addtomap(1, newobject);     myobject newobject = new myobject();     newobject.setinfo(3,4);     mytable.addtomap(2, newobject);     myobject newobject = new myobject();     newobject.setinfo(5,6);     mytable.addtomap(3, newobject);     myobject newobject = new myobject();     newobject.setinfo(7,8);     mytable.addtomap(4, newobject); } 

the problem when want check values:

for (table table : tablelist) {     int[] info = table.getobject(4).getinfos();     log.d("tag","4: {" + info[0] + ", " + info[1] + "}"); } 

when i've got 1 table object ok. problem begins when have 2 or more objects. in case 2 elements after interactions (not important in case) have problem.

each time, last object map of objects - newobject number 4 on first table object has value equal 1st object value of 2 element. second table object , myobject objects ok.

i trying everything, , don't see else why asking here.

can tell me going on here getting error?

i have been checking it, , works me. problem not way table defined (the code shown), in way you're using it. you're modifying instance of myobject after add first table.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -