How can I return a different object in a method parameter?
Ans : There are two ways. The obvious way is “just add another level of 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
- The GetInfo method can return the full html for the loaded page, using OuterHtml as the parameter I pass in. What if I only want a certain part of the html (for instance, the tag) ?
- Can I override the equals method or clone method from class Object to take a parameter or return a value of the type that I specify?
- How can I return a different object in a method parameter?