java - Accessing private field in a subclass -
i'm creating class extends propertychangesupport
. want override firepropertychange()
:
firepropertychange implemented in propertychangesupport:
public void firepropertychange(string propertyname, object oldvalue, object newvalue) { if (oldvalue == null || newvalue == null || !oldvalue.equals(newvalue)) { firepropertychange(new propertychangeevent(this.source, propertyname, oldvalue, newvalue)); } }
my intended override of firepropertychange
:
public void firepropertychange(string propertyname, object oldvalue, object newvalue) { if (oldvalue == null || newvalue == null || !oldvalue.equals(newvalue)) { firepropertychange(new joystickpropertychangeevent(this.source, propertyname, oldvalue, newvalue)); //compile error: source not visible } }
joystickpropertychangeevent
class created , extends properychangeevent
.
the problem intended implementation not compile because source private , has no getters
in propertychangesupport
, subclasses have no access it. cannot modify propertychangesupport
's code.
is there more elegant way of solving having private copy of source field of subclass?
related question: how access private variables of class in subclass?
i question design of this.
the method trying override has been made private reason, if change implementation wouldn't advise since don't know impact have elsewhere.
Comments
Post a Comment