« My Muse | Main | Wha? You can DO that?!?! »

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....