Suppose we have the following Java interface:
// Java
public interface Foo {
<T> T bar(Class<T> c);
}
How should I extend it in Scala? Writing
// Scala
class FooString extends Foo {
override def bar(c: Class[String]): String = "hello, world";
}
will cause the compiler to throw "class FooString needs to be abstract, since method bar in trait Foo of type [T]
(Class[T])T is not defined."
Thanks in advance!
Update: The ugly truth is: I've misunderstood generics in Java.
In any case, the solutions to my woes are shown in both Nicolas' and Walter's answers, although I prefer Walter's answer better 'cos it's less verbose.
Thanks Nicolas and Walter! :)