Poor interaction between self-referencing types and restricted wildcards

This case seems to be different when the Eclipse Java compiler breaks javac. The only question for me is a bug in the JLS or javac.

interface EndoFunctor< C, FC extends EndoFunctor< C, FC > > { /*...*/ }
interface Algebra< C, FC extends EndoFunctor< ? extends C, FC > > { /*...*/ }


The second line is compiled in Eclipse but not compiled in javac with a message that "the type of the FC parameter is not within its bounds".

FC declared for extension EndoFunctor <? extends C, FC> and the boundary on FC is that it extends EndoFunctor <D, FC> for the inferred D, what in this case? extends C. I think javac doesn't understand that the wildcard represents the same unknown type in both contexts. Eclipse does, though!

Apparently the following issue is with javac:

interface EndoFunctor< C, FC extends EndoFunctor< ? extends C, FC > > { /*...*/ }


but this is a weaker definition than I want for this interface.

I could also try

interface Algebra< C, D extends C, FC extends EndoFunctor< D, FC > >


but this approach makes me carry this extra D parameter through everywhere.

What to do?


source to share

1 answer

What to do?

Here are a couple of pragmatic solutions.

  • Try using javac

    from the latest Java 7 patch. I remember hearing some javac compiler errors in Java 6 that were only fixed in Java 7 ... but I don't know the list, (And the Java error database is hopeless when searching ... )

  • Put it down and use one of the two alternatives you've already found to "work".



All Articles