I've been using the new features in Java 1.5 more and more in all of my projects, most recently in a Java AWT project. It's been a while I last worked with AWT, I must say that. The more I've used generics and annotations in practice, the more I've started liking them. However, typed events are nowhere to be found. It is somewhat understandable, because EventObject source could theoretically be anything. But in practice, you often times have just one (known) event source - which can be an interface - so it'd be nice to specify the type of the source when you create the event. Though missing from JRE, it's a simple matter to implement a typed EventObject yourself, like this for example:
public class TypedEvent<T> extends EventObject {
public TypedEvent(T source) {
super(source);
}
@SuppressWarnings("unchecked")
public T getSource() {
return (T)super.getSource();
}
}
... which they *could* have simply added to EventObject itself.
Posted by thoughts at January 9, 2006 11:43 AM | TrackBack