I need to override a Java method from a Java interface which makes use of a vararg parameter:
public interface Function<T> {
T apply(Object... var1);
}
When I try to implement the method apply in Scala like follows
class ScalaFunction extends Function[String] {
override def apply(args: Object*): String = args.toList match {
// impl
}
}
I get a "java.lang.AbstractMethodError: null" error during run-time.
This is what I already tried:
- using
@varargs args
Scala annotation which should generate a Java-friendly delegate method => resulted in the same error using a self-provided delegate method
def apply(args: Array[Object]): Unit = apply(args: _*)
which was actually successfully called, but I'm not able to use String as return type because then the compiler yields a
Error:(13, 7) double definition: def apply(args: Array[Object]): String at line 20 and override def apply(args: AnyRef*): String at line 13 have same type after erasure: (args: Array[Object])String
The calling Java code looks like this:
Object[] args = //...
Object returnValue = function.apply(args);
Any ideas?
See this Gist for an example: https://gist.github.com/mrueegg/f191e547bee6a24a6bcf
Thanks, Michael