The following shows some test code that I am running. In the debugger I am inspecting the ArrayList "mrfThrotso" after each mrfThrotso.add(test) call.
The first two adds put two copies of the same object in and work as expected. Before the third mrfThrotso.add(test). I changed one member of the object and upon inspection of mrfThrotso, all elements have that change.
Is this how it is supposed to work?
// 777 experimenting code
ArrayList<structLocoLTR> mrfThrotso = new ArrayList<>();
structLocoLTR test = new structLocoLTR();
structLocoLTR read = new structLocoLTR();
Boolean bT = new Boolean( false );
mrfThrotso.clear();
test.Loco = "1234";
test.nThrotNum = 0;
test.AutoStart = "Yes";
mrfThrotso.add( test );
mrfThrotso.add( test );
test.nThrotNum = 1;
mrfThrotso.add( test );
test.Loco = "2345";
public class structLocoLTR
{
//
//
//
String Loco;
String Track;
String Role;
String Direction;
String Photo;
String AutoStart;
//
//
//
int nThrotNum;
int nCol;
int nRow;
}