I think this is possible, and this can be done using the compiler plugin to look something like
@extension implicit def whatever[A](a: A) = new { ... }
But I donβt know if anyone else wrote such a plugin ...
UPDATE:
If I compile this file:
object Main { implicit def option[A](a: A) = new { def id = a } def foo(x: String) = x.id }
and decompile the code for foo , reflection is still involved:
F:\MyProgramming\raw>javap -c Main$ Compiled from "Main.scala" public final class Main$ extends java.lang.Object implements scala.ScalaObject{ public static final Main$ MODULE$; public static {}; Code: 0: new #9;
Compare with
object Main2 { class Whatever[A](a: A) { def id = a } implicit def option[A](a: A) = new Whatever(a) def foo(x: String) = x.id }
And decompilation:
F:\MyProgramming\raw>javap -c Main2$ Compiled from "Main2.scala" public final class Main2$ extends java.lang.Object implements scala.ScalaObject{ public static final Main2$ MODULE$; public static {}; Code: 0: new #9;
Alexey romanov
source share