Imitation of a link with wrappers.
One way that you can have this behavior in some way simulated is to create a common shell.
public class _<E> { E ref; public _( E e ){ ref = e; } public E g() { return ref; } public void s( E e ){ this.ref = e; } public String toString() { return ref.toString(); } }
I am not too convinced of the meaning of this code, I could not help it, I had to code it :)
So there it is.
Sample Usage:
public class Test { public static void main ( String [] args ) { _<Integer> iByRef = new _<Integer>( 1 ); addOne( iByRef ); System.out.println( iByRef );
It's funny that the common name of the wrapper class is "_", which is a valid class identifier. Thus, the declaration reads:
For an integer:
_<Integer> iByRef = new _<Integer>( 1 );
For the string:
_<String> sByRef = new _<String>( "Hola" );
For any other class
_<Employee> employee = new _<Employee>( Employee.byId(123) );
Methods "s" and "g" mean a lot and get: P
OscarRyz Jan 10 '09 at 15:47 2009-01-10 15:47
source share