Skip to content

Instantly share code, notes, and snippets.

@mrueegg
Created September 21, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrueegg/f191e547bee6a24a6bcf to your computer and use it in GitHub Desktop.
Save mrueegg/f191e547bee6a24a6bcf to your computer and use it in GitHub Desktop.
Calling overriden Scala method of Java interface with varargs parameter resulting in AbstractMethodError in Scala 2.11
lazy val root = (project in file(".")).
settings(
name := "hello",
version := "1.0",
scalaVersion := "2.11.4"
)
fork in run := true
javaOptions in run += "-ea"
public interface JavaFunction<T> {
T apply(Object... var1);
}
public class Main {
public static void main(String[] args) {
JavaFunction f = new ScalaFunctionImpl();
assert("1,2,3".equals(f.apply("1", "2", "3")));
}
}
import scala.annotation.varargs
class ScalaFunctionImpl extends JavaFunction[String] {
// Manual delegate method is not allowed to have String return type
// def apply(args: Array[Object]): Unit = apply(args: _*)
// @varargs
override def apply(args: AnyRef*): String = args.mkString(",")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment