Skip to content

Instantly share code, notes, and snippets.

@superbobry
Last active September 25, 2017 20:36
Show Gist options
  • Save superbobry/41032af161d7e0c65a51f79eeb3af1ec to your computer and use it in GitHub Desktop.
Save superbobry/41032af161d7e0c65a51f79eeb3af1ec to your computer and use it in GitHub Desktop.
Specializing a method on a value class
import scala.{specialized => spec}
package object foo {
class ImplicitTest(val n: Nothing) extends AnyVal {
def foo[@spec(Double) T](size: Int)(f: Int => T): Array[T] = {
f(42)
???
}
}
}
public class foo.package$ImplicitTest$ {
public static foo.package$ImplicitTest$ MODULE$;
public static {};
Code:
0: new #2 // class foo/package$ImplicitTest$
3: invokespecial #18 // Method "<init>":()V
6: return
public final <T> java.lang.Object foo$extension(scala.runtime.Nothing$, int, scala.Function1<java.lang.Object, T>);
Code:
0: aload_3
1: bipush 42
3: invokestatic #29 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
6: invokeinterface #35, 2 // InterfaceMethod scala/Function1.apply:(Ljava/lang/Object;)Ljava/lang/Object;
11: pop
12: getstatic #40 // Field scala/Predef$.MODULE$:Lscala/Predef$;
15: invokevirtual #44 // Method scala/Predef$.$qmark$qmark$qmark:()Lscala/runtime/Nothing$;
18: athrow
...
}
public final class foo.package$ImplicitTest {
public scala.runtime.Nothing$ n();
Code:
0: aload_0
1: getfield #16 // Field n:Lscala/runtime/Nothing$;
4: areturn
public <T> java.lang.Object foo(int, scala.Function1<java.lang.Object, T>);
Code:
0: getstatic #26 // Field foo/package$ImplicitTest$.MODULE$:Lfoo/package$ImplicitTest$;
3: aload_0
4: invokevirtual #28 // Method n:()Lscala/runtime/Nothing$;
7: iload_1
8: aload_2
9: invokevirtual #32 // Method foo/package$ImplicitTest$.foo$extension:(Lscala/runtime/Nothing$;ILscala/Function1;)Ljava/lang/Object;
12: areturn
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment