"unexpected type" error in typed class definition
Hi,
Simplified example is:
publicclass Test{
publicstaticinterface MyInterface{}
publicstaticinterface MyInterface2extends MyInterface{}
//This is fine
publicstaticclass MyClass1<Mextends MyInterface, Nextends M>{}
//This is fine
publicstaticclass MyClass2<Mextends MyInterface & MyInterface2, Nextends M>{}
//But this is not ?
publicstaticclass MyClass3<Mextends MyInterface, Nextends MyInterface2 & M>{}
}
Anyone know why javac tells me:
Test.java:11: unexpected type
found: type parameter M
required: class
when it gets to MyClass3?
Thanks
[1898 byte] By [
matchamia] at [2007-11-27 4:31:11]

# 1
According to the JLS :
>Type variables have an optional bound, T & I1 ... In. The bound consists of either a type variable, or a class or interface type T possibly followed by further interface types I1 , ..., In
So if your bound contains a type variable, you can't add anything else to it.
# 2
Thanks!, although actually its the following sentence:
...and that a class type or type variable may only appear in the first position.
that explains it!
So, if I reverse the order and it becomes
N extends M & MyInterface2
then I encounter the constraint that you have highlighted, but why does this have to be?
The only reason that I can see is that the compiler can't check the erasures of the type variable because it's not a concrete class, but surely that can be handled by the compilation of the instance and isn't relevant to the compilation of the class signature?