java - Assigning value of an object to another - they mustn't point same adresses at memory -


I have a problem getting a new value of an object. I have such code:

  ... timeline [] offspringScheduleOne = new timeline [AVAILABLE_CLASSROOMS]; ... offspringScheduleOne [i] = jean .get (geneonindex) .getSchedule () [i]; ...   

Scheduling up to that assignment appeals [i] and jean. After GT (GeneOnInX), .getSchedule () [i] indicates same memory address . I want to: offspringScheduleOne [i] should get the value of genes.get (geneOneIndex) .getSchedule () [i] , they will not be identical, They should have the same value .

TimeSchedleue class:

  Expands the public class time-scheduling algorithm parameter {public int [] [] timetable = new int [day] [hours]; // day and HOS are the final variables obtained from algorithm parameters [] [] getTimetable () {return timetable; } Public Zero Sitemet (Ent [] [] Timetable) {this.timetable = timetable; }}   

How can I do this?

This is actually copying value - but you understand it What would that value be?

offspringScheduleOne [0] is not the value of the timeddevil object one reference > Object is in. There is no expression in Java which is an object which is an object. It's really important that you understand it.

Now, if you want to copy the object, you have to do it yourself, for example, you can use the clone () method can include time-schedulable , and write:

  offspringScheduleOne [i] = gene.jet (geneOneIndex) .getSchedule () [i] .clone () ;   

In other words, create a clone of the existing object, and then set offspringScheduleOne [i] in the context of that newly created object. Of course, if any area in the timeline is a reference type field, then you have to consider whether or not you need to clone that object ... < / P>

... or you can add a constructor and call that call or any other method. But you should be absolutely clear that the assignment operator is copying the value, but this value is a reference.

EDIT: OK, now you have posted timestamp , some suggestions:

Comments