I’m trying to extend a Java class. One of the methods I need to override has a strange parameter:
public void doStuff(Foo input) {...}
Foo is an interface defined as follows:
public interface Foo<T extends Foo<T, U>, U extends Bar<U>> {...}
I’ve never seen a recursively-defined type like this before. I gather this is called a self-bounded generic in Java or F-bounded polymorphism in Scala.
IntelliJ generates the override like this:
override def doStuff(input: Foo[_, _ <: Bar[_]]): Unit = {...}
The presentation compiler seems to accept this, but the code does not actually compile. I get the following error:
method doStuff overrides nothing
I’ve tried adding additional upper type bounds for the Foo parameter. I’ve also tried declaring a type alias for Foo. Nothing has worked so far.
My current workaround is to extend the class in Java and have it call Scala methods that do the actual work (luckily, I don’t need to consume the Foo parameter - I just need to override the method). Of course, this is far from ideal. Is there a way to override the doStuff
method in a way that will actually compile?