Title might be little misleading since in java we pass always by value, but we can mimic passing by reference.
/**
* This class allows us to pass values by reference ranter than value.
* Not directly as java just passes reference of the object by value but indirecly
* @author Greg
*
* @param
*/
public class IndirectReference {
public E ref;
public IndirectReference(E ref) {
this.ref = ref;
}
public void set(E ref) {
this.ref = ref;
}
}
Example usage
Just a snippet copied from my interpreter
IndirectReference signal = new IndirectReference(ControlSignal.NOOP);
if(signal.ref == ControlSignal.BREAK){
break;
}
Leave a Reply