Hello. If someone could please tell me why I am seeing different results with the following code:
/**
* This works fine...
*/
SomeObject [] s = new SomeObject[2];
s[0] = new SomeObject();
s[1] = new SomeObject();
s[2] = new SomeObject();
s[0].setSomething("Some value here");
s[1].setSomething("Another value here");
s[2].setSomething("And yet another value here");
/**
* But this only stores the last value in each of the array
* elements
*/
String [] SomeArray = {"one", "two", "three"}
int numOfObjectsNeeded = 3
SomeObject [] t = new SomeObject();
for (int i=0; i<numObjectsNeeded; i++) {
t[i] = new SomeObject();
t[i].setSomething(UniquePrimeativeValueFromSomeArray[i]);
}
/**
* Now if I look into each of the three object array elements, I
* see that "three" has been written to all of them!
*/
The first part works just fine. Ive even tried it with Vector() and ArrayList() but I get the same results. I'm obviously doing something wrong... any ideas?
Thanks for reading,
Tommy T