Accessing the value of a manipulated List member
I store my "Cars" in my "CarCollection" (that is a List<Car>). What I
intend to do is accessing every cars' recent data member value even if
they were changed after a while. So, by using a collection, I want to
access my updated cars everytime I feel like.
I've added my Cars into the List as soon as they're created. After a
while, when I access the List and try to get the value of some car's data
member I get the outdated (same value as it is first created) value but I
want to newly-manipulated value not the old one.
It seems like I can't do it in my way. How can I achieve what I want in a
problem like this?
PS: Manipulation is done by a new Thread
Example:
Car newCar = new Car();
newCar.setColor(Color.Blue);
CarCollection.Add(newCar);
..
A new thread is called and it changed newCar's color to Red
..
After a while
..
newCar.getColor(); // Blue
With what approach can I get Red?
No comments:
Post a Comment