I come from a C++ background. In C++ I can store a memory adress which I just new'd in a global array and re-use it later. For example, say I have two classes X, Y and I create two objects x, y. The global array StoreAddresses[2] is defined as:
uint32_t StoreAddresses[2]; I write:
X * x = new X(); Y * y = new Y(); StoreAdresses[0] = (uint32t *) x; //for example, 0x12345678 StoreAdresses[1] = (uint32t *) y; //for example, 0x12345698 Anywhere in my program, I can retrieve the data written in memory by calling:
X * stored_x = (X*)StoreAdresses[0]; Y * stored_y = (Y*)StoreAdresses[1]; How can I accomplish that in Java? Appreciate the help!
unsafeas Peter Lawrey states -- 1+ to him), but better would be for you to learn the ways of Java and adapt your coding to its strengths, not its weaknesses.XandYin a static field, instead of mucking around with memory addresses.X x = new X(); x.doThis()is equivalent to C++X* x = new X(); x->doThis(). Always think in Object pointers and arrow access.