Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodError when calling implementation trait method from Java #6050

Closed
scabug opened this issue Jul 9, 2012 · 4 comments
Closed

NoSuchMethodError when calling implementation trait method from Java #6050

scabug opened this issue Jul 9, 2012 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jul 9, 2012

I ran into a NoSuchMethodError when trying to implement my own "implementation trait" code, patterned after TraversableLike.

The following Java and Scala code compiles without errors:

ScalaTest.scala:

trait MyTrait[T, This <: MyTrait[T, This]] {
  def x: This

  def myVal(): This = x

  def hello() = {System.out.println("HELLO")}
}

class MyClass[T]() extends MyTrait[T, MyClass[T]] {
  def x : MyClass[T] = new MyClass
}

object ScalaTest {
    def main(args: Array[String]) {
       val x : MyClass[Int] = new MyClass[Int]
       x.hello()
       x.myVal()
    }
}

JavaTest.java:

public class JavaTest {
    public static void main(String[] args) {
       MyClass<Integer> x = new MyClass<Integer>();
       x.hello();
       x.myVal();
    }
}

The ScalaTest program works correctly:

$ scala ScalaTest
HELLO

The JavaTest program throws a NoSuchMethodError when run:

$ scala JavaTest
HELLO
java.lang.NoSuchMethodError: MyClass.myVal()LMyClass;
	at JavaTest.main(JavaTest.java:5)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78)
	at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88)
	at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78)
	at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:56)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

scabug commented Jul 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6050?orig=1
Reporter: Josh Rosen (joshrosen)
Affected Versions: 2.9.2, 2.10.0-M4
Attachments:

@scabug
Copy link
Author

scabug commented Jul 9, 2012

@acruise said:
Observed on 2.10.0-M4 too, downloading the nightly...

@scabug
Copy link
Author

scabug commented Jul 9, 2012

@acruise said:
Observed on 2.10.0-20120708-165613-f82a1d122c

@scabug
Copy link
Author

scabug commented Jul 9, 2012

@paulp said:
This is #3452.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants