Link to home
Start Free TrialLog in
Avatar of allelopath
allelopath

asked on

Override method problem - StackOverflowError

I have classes like so:
public class ParentClass {
    private Object myObject;

    public void setMyObject(final Object object) {
	this.myObject = object
    }
}

public class ChildClass extends ParentClass {
    @Override
    public void setMyObject(final Object object) {
        setMyObject(object);
        // do other stuff
    }
}

Open in new window


I want to override the method so that I can do some things not in the parent class method, but first I have to make sure that myObject gets set. As it is, this code gives a StackOverflowError because ChildClass.setMyObject() is called ad infinitum. I cannot change the access of myObject to protected. How is this done?
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial