The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.



Posted by karthik on January 23, 2001 at 10:00 PM

I have a strong feeling that it cannot be done but am not sure.
Since in Java, it's pass by value, i feel it cannot be done.
Yeah array is definitely a solution but i'm just looking for a simple java equivalent of C code where u pass the "pointers" and swap it.


> Hi,
> this question is for me very interesting too.
> What about so a function?:

> static Object[] swap(Object a, Object b) {
> a.getClass().getClassLoader()[] r = {b,a} ; // (1)
> return r ;
> }

> (1) doesn't work. I don't know how this can be done. It is posible? But if it would work, swap would be a function for all objects, and then:

> AnyObjectType temp[] = swap(a,b) ;
> a = temp[0] ; a = temp[1] ;


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us