reference so it points to a different object back in the calling code?
indirection”. Wrap the object in another class, whose purpose is simply to be passed as a parameter, allowing the nested object reference to be modified. The second alternative is a clearer variant of this. Pass in a single element array. Since arrays are objects, this works. void jfoo(Object ref[]){ ref[0] = new Object(); } … Object kludge[] = new Object[1]; kludge[0]= myObj; jfoo(kludge); if (kludge[0] == myObj) … else … Note that changing a global variable/object inside a method is an egregious programming practice; it usually violates basic OOP constructs.
Related Questions
- If I put an extrn directive in my code, flat assembler emits the external reference to the object file even if the code doesn reference the symbol, how can I avoid it?
- How, then, can I pass an object to a method, and have the method change the reference so it points to a different object back in the calling code?
- reference so it points to a different object back in the calling code?