Tuesday, January 29, 2013

How to change a variables value from a array? (is it even possible?)

This is a little confusing question to express, its probably more Java
then gwt specific, but given that gwt is really javascript, I am not
quite sure what domain it falls under.


So
ArrayList<Object> fieldList = new ArrayList<Object>();

I then dump a lot of different variables to this array.

fieldList.add(ObjectsURL); //string
fieldList.add(X); //int
fieldList.add(Y); //int
...
If I change the variable, the values in the array change
too...confirming the array stores a reference to the memory, rather
then value itself.


However, if I then retrieve data from the array then set that...

Object object = ((String)this.fieldList.get(0));

Then set object

object = "meeep!"

ObjectsURL is not set to "meep!" but rather it retains its original
value.

I assume this is because the "object" is not referencing the original
variable anymore, that instead its pointing to a new immutable string
in the memory.
All expected Java behavior I think....but then, how would I go about
setting the actual original variable? is this possible in java? (is it
possible in javascript?). If not, is there an alternative method to
achieve the same thing?

I hope my question explains the problem well enough.

My use-case is trying to make a client only serialization/
deserialization system for a bunch of my objects. I was hoping to put
all the fields into a arraylist I could retrieve for both reading and
writting....thus avoiding having to hard-code long lists of
field[0]=blah and blah=field[0] and then going though constant pains
of needing to renumber them each time I add a new field before
another.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment