Skip to content

Instantly share code, notes, and snippets.

@ankurdave
Created October 10, 2015 03:00
Show Gist options
  • Save ankurdave/f596d4480830ffcf4b31 to your computer and use it in GitHub Desktop.
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`
public class A<T> {
public A(T t) {
this.t = t;
}
public T t;
public void print() {
System.out.println(t.getClass().getSimpleName() + " " + t);
}
}
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
}
}
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