Created
July 9, 2012 22:21
-
-
Save JoshRosen/3079407 to your computer and use it in GitHub Desktop.
Scala NoSuchMethodError when using traits from Java
This file contains hidden or 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 JavaTest { | |
public static void main(String[] args) { | |
MyClass<Integer> x = new MyClass<Integer>(); | |
x.hello(); | |
x.myVal(); | |
} | |
} |
This file contains hidden or 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
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment