Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor
Accepted Solution

Vector behavior

I have been using a Vector as a vehicle for transporting data between tasks since it can carry different objects.

 

I discovered the following:

 

1. Update String array  with values

2. Put the array into the Vector.

3. Change the array

 

Result:  The array is changed "inside" the Vector simply by changing it outside of the Vector. This came as absolute surprise to me. Is this behavior "by design"??  Played havoc with my code.

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
Posts: 226
Registered: ‎10-01-2011
My Device: Passport

Re: Vector behavior

To me it makes sense since a vector is a collection of pointers, you are not actually storing the data in the vector but pointers to the data. If you change the data the vector points to then you would expect the vector to reflect your changes. You need to new your array to break free of this.

Developer
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Vector behavior

thanks crispyoz.

I suspected something like that. What makes it a bit confusimng is when you passes it to a new thread the pointers are still valid. And I did not find any reference in the documentation to thhis.

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vector behavior

This is standard Java,  Same thing will happen in any Java platform. 

 

I suggest we call these references and not pointers.  Pointers mean something else in other languages.