|
Re: Self-bounding generics
|
Posted: Nov 16, 2005 3:25 AM
|
|
Someone asked this question already. Why is this not the 'Curiously Recurring Template Pattern' ?
public class PropertySupportAspect<T extends PropertySupportAspect<T>> {
PropertyChangeSupport support = new
PropertyChangeSupport(this);
public void addPropertyChangeListener
( PropertyChangeListener listener){
support.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
support.addPropertyChangeListener(propertyName,
listener);
}
public void removePropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
support.removePropertyChangeListener(propertyName,
listener);
}
public void removePropertyChangeListener
(PropertyChangeListener listener) {
support.removePropertyChangeListener(listener);
}
public void hasListeners(String propertyName) {
support.hasListeners(propertyName);
}
public void firePropertyChange( Bean b,
String property,
String oldval,
String newval) {
support.firePropertyChange( property,
( oldval == null ) ?
oldval :
new String(oldval),
new String(newval));
}
}
class Bean extends PropertySupportAspect<Bean>{
private String name;
public String getName() {
return name;
}
public void setName( String name ) {
firePropertyChange( this,
"name",
getName(),
name );
this.name = name;
}
}
|
|