Created
September 21, 2015 20:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val root = (project in file(".")). | |
settings( | |
name := "hello", | |
version := "1.0", | |
scalaVersion := "2.11.4" | |
) | |
fork in run := true | |
javaOptions in run += "-ea" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface JavaFunction<T> { | |
T apply(Object... var1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
JavaFunction f = new ScalaFunctionImpl(); | |
assert("1,2,3".equals(f.apply("1", "2", "3"))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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