Array elements behaving as though they were all the same object
I have an Array of Paint objects that is created in one class and a single
paint object that is created in another class. Initially i assign each
element of the paint object array the value of the single paint array.
After I do that, all the paint object elements in the array act as though
they were all the same object. Meaning that any change applied to any of
the elements in this array is also applied to all the other elements of
the array. Here is the code to make it clearer: This is where I initialize
all the elements of the paint array with one single paint object.
for (int i = 0; i < 9; i++) {
bmpHandler.fillPaint[i] = pathDraw.fillPaint;
}
Later I change one element of the array
bmpHandler.fillPaint[3].setShader(bmpShader);
Now when I check with the Object.equals(Object) method I get, that all the
elements in the array are the same. Why is this happening, and how can I
prevent this from happening.
No comments:
Post a Comment