" /> Rock Star Programmer: March 2006 Archives

Main | June 2006 »

March 27, 2006

Generic confusion

I've been using Java 5 generics for a while now, and I thought I had a pretty good handle on them. Then I ran across the need to declare a parameter type wildcard that both extends a class and implements an interface. Now, I already knew that you have to use extends instead of the more intuitive implements, even with an interface:

public class Foo<T extends MyInterface>

And I'm ok with that. Really. So I tried the naive approach to my problem:

public class Foo<T extends MySuperclass, MyInterface>

Which just doesn't work. I didn't try compiling it, but strangely enough, my IDE doesn't mark it as a syntactic error - it marks the interface as "unused". The correct syntax for this case is:

public class Foo<T extends MySuperclass & MyInterface>

Huh? I just had it pointed out to me that "," is used to separate types, so couldn't be used in this case. So "&" it is....

March 22, 2006

My Muse

For anybody wondering about the title of this blog, see my inspiration. The content is pretty straight forward, but the title is flat out ridiculous... So I did I Google search, and found lots of other blogs and articles about how to be a "Rock Star Programmer". None of which (unfortunately) have anything to do with sex, drugs, or rock and roll. It's all about self-perception, apparently...or maybe just wishful thinking?

March 16, 2006

We can rebuild him! But...er...we ain't gonna...

We've been building a filterable, sortable JTree (sort of like swingx's JXTree, but actually working). Of course we ran head-first into the common JTree problem - any structureChanged event collapses the tree. So we filter the tree - and it collapses. Darn. But don't worry! Those clever swing guys, they figured out how to fix it, as the following comment shows (JTree, line 3165) :

// NOTE: If I change this to NOT remove the descendants
// and update BasicTreeUIs treeStructureChanged method
// to update descendants in response to a treeStructureChanged
// event, all the children of the event won't collapse!

Of course, the fix involves rewriting BasicTreeUI. Which is subclassed by every look and feel out there, so, of course, only Sun can fix it. Which they didn't bother to do. But hey, they left us that great comment. Thanks guys!