Monday, July 10, 2006

 

The power of inner classes

When Java 1.1 came out I was a little intimidated by inner classes. I think the biggest reason was you couldn't (at the time) represent them in the UML tools. I did a lot of AWT programming then and trying to do event handling with out them got ugly. So eventually I learned them and began to see how useful they were. For example, how cool is this:

final javax.swing.JList tracesList = new javax.swing.JList() {
public String getToolTipText( MouseEvent e ) {
int i = locationToIndex( e.getPoint() );
Object o = getModel().getElementAt(i);
return o.toString();
}
};

You can override just one method right there in the middle of your code.

But inner classes aren't used often on the server side. I bet part of the answer is that it makes it harder to do all that UML modeling! :-) Hopefully my recent work with Swing will remind me about the types of inner classes I have available when doing server side development.

BTW, that is real code that I am working on for the Chime project. Note the { is not my prefered way and neither is the ( placement so I need to retrain my brain/emacs/netbeans everytime I work on it!

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?