I'm creating a class that extends PropertyChangeSupport
. What I currently want to do is override firePropertyChange()
:
firePropertyChange as it is 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 is not visible
}
}
JoystickPropertyChangeEvent
is a class that I created and that extends ProperyChangeEvent
.
The problem is that my intended implementation does not compile because source is private and has no getters
in PropertyChangeSupport
, so subclasses have no access to it. I cannot modify PropertyChangeSupport
's code.
Is there a more elegant way of solving this than having a private copy of source as a field of my subclass?
Related question: How to access the private variables of a class in its subclass?