This case seems to be another one where Eclipse's Java compiler crushes javac. The only question for me is whether it's a bug in JLS or javac.
interface EndoFunctor< C, FC extends EndoFunctor< C, FC > > { /*...*/ }
interface Algebra< C, FC extends EndoFunctor< ? extends C, FC > > { /*...*/ }
The second line compiles in Eclipse, but fails to compile in javac with the message that "type parameter FC is not within its bound".
FC is declared to extend EndoFunctor< ? extends C, FC >, and the bound on FC is that it extend EndoFunctor< D, FC > for the inferred D, which in this case is ? extends C. I think javac doesn't realize that the wildcard represents the same unknown type in both contexts. Eclipse does, though!
Apparently the following gets around the problem in javac:
interface EndoFunctor< C, FC extends EndoFunctor< ? extends C, FC > > { /*...*/ }
but this is a looser definition than I want for that interface.
I could also try
interface Algebra< C, D extends C, FC extends EndoFunctor< D, FC > >
but that approach forces me to carry that extra type parameter D through everywhere.
What to do?
What to do?
Here are a couple of pragmatic solutions.
Try using javac from the latest patch release of Java 7. I recall hearing of certain javac compiler bugs in Java 6 that were only fixed in Java 7 ... but I don't know of a list. (And the Java Bugs Database is hopeless at searching ...)
Put up with it, and use one of the two alternatives that you've already found that "work".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With