I would like to create a void method that could change the value of the given parameter. I Tried to modify it in the method but it didn't work because it's modifying a copy of the variable.
I Know I can do it in c++ as following :
void Foo::myMethod(MyObject& obj);
I know I can use the return statement in my methods but I would Like to know if there's a way to do as above in java and here is what I tried :
public class LocalCallbackTest {
public static class MyClass {
    private MyClass oldClass = null;
    private MyClass newClass = null;
    private int value = 0;
    public MyClass() {
    }
    public MyClass(MyClass old) {
        this();
        oldClass = old;
    }
    /**
     * @return the newClass
     */
    public MyClass getNewClass() {
        return newClass;
    }
    /**
     * @return the oldClass
     */
    public MyClass getOldClass() {
        return oldClass;
    }
    /**
     * @return the value
     */
    public int getValue() {
        return value;
    }
    /**
     * @param newClass the newClass to set
     */
    public void setNewClass(MyClass newClass) {
        this.newClass = newClass;
    }
    /**
     * @param oldClass the oldClass to set
     */
    public void setOldClass(MyClass oldClass) {
        this.oldClass = oldClass;
    }
    /**
     * @param value the value to set
     */
    public void setValue(int value) {
        this.value = value;
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (oldClass != null)
            sb.append("old class : \n\t").append(oldClass.getValue()).append("\n");
        if (newClass != null)
            sb.append("new class : \n\t").append(newClass.getValue()).append("\n");
        sb.append("actual class : \n\t").append(value).append("\n");
        return sb.toString();
    }
    private MyClass rollBack() {
        if (this.oldClass != null) {
            this.oldClass.setNewClass(this);
            return oldClass;
        }
        return this;
    }
    private MyClass nextMember() {
        if (this.newClass != null) {
            this.newClass.setOldClass(this);
            return newClass;
        }
        return this;
    }
    public static boolean rollBack(MyClass param) {
        if (param != (param = param.rollBack())) {
            return true;
        }
        return false;
    }
    public static boolean nextMember(MyClass param) {
        if (param != (param = param.nextMember())) {
            return true;
        }
        return false;
    }
    public static void test(int i) {
        i++;
    }
}
public static void main(String[] args) {
    MyClass test = new MyClass();
    test.setValue(0);
    for (int i = 1; i <= 5; i++) {
        MyClass test2 = new MyClass();
        test2.setValue(i);
        test2.setOldClass(test);
        test.setNewClass(test2);
        test = test.getNewClass();
        System.out.println(test.getValue());
    }
    int val=2;
    MyClass.test(val);
    System.out.println(val);
    }
}
thank you for your Help.
 
    