Created
October 10, 2015 03:00
-
-
Save ankurdave/f596d4480830ffcf4b31 to your computer and use it in GitHub Desktop.
Check that Scala autoboxes primitives before passing them to Java generic classes. Run with `sbt run`
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 A<T> { | |
public A(T t) { | |
this.t = t; | |
} | |
public T t; | |
public void print() { | |
System.out.println(t.getClass().getSimpleName() + " " + t); | |
} | |
} |
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
object B { | |
def main(args: Array[String]): Unit = { | |
f(1) | |
f(1.0) | |
f("foo") | |
} | |
def f[T](t: T): A[T] = { | |
val res = new A[T](t) | |
res.print() | |
res | |
} | |
} |
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
name := "ScalaJavaGenericInterop" | |
version := "0.1-SNAPSHOT" | |
organization := "com.ankurdave" | |
scalaVersion := "2.10.4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment