在 Scala 中如何在执行期间找到有效的隐式方法、声明和转换
In Scala how to find THE effective implicit methods, declarations and conversions during an execution
试图理解 akka marshalling/unmarshalling 并发现了很多在后台和引擎盖下进行的 scala 隐式魔法。
问题:
有没有办法找到执行期间哪些隐式构造有效。
需要知道的事情:
- 哪些隐式声明和转换有效
- 声明的地方
我在想的是 IDE 插件吗?要在代码调试期间使用?
我认为这将有助于理解 akka marshalling/unmarshalling,而且在使用复杂隐式特征的地方它通常也很有用。
在编译时选择隐式。
与-Xlog-implicit-conversions
:
scala 2.13.0-M5> "42".toInt
^
applied implicit conversion from String("42") to ?{def toInt: ?} = implicit def augmentString(x: String): scala.collection.StringOps
res0: Int = 42
scala 2.13.0-M5> "42".toInt //print<TAB>
scala.Predef.augmentString("42").toInt // : Int
-Xlog-implicits
说明隐式不适用的情况。
IntelliJ 有 "show implicits".
试图理解 akka marshalling/unmarshalling 并发现了很多在后台和引擎盖下进行的 scala 隐式魔法。
问题: 有没有办法找到执行期间哪些隐式构造有效。 需要知道的事情: - 哪些隐式声明和转换有效 - 声明的地方
我在想的是 IDE 插件吗?要在代码调试期间使用?
我认为这将有助于理解 akka marshalling/unmarshalling,而且在使用复杂隐式特征的地方它通常也很有用。
在编译时选择隐式。
与-Xlog-implicit-conversions
:
scala 2.13.0-M5> "42".toInt
^
applied implicit conversion from String("42") to ?{def toInt: ?} = implicit def augmentString(x: String): scala.collection.StringOps
res0: Int = 42
scala 2.13.0-M5> "42".toInt //print<TAB>
scala.Predef.augmentString("42").toInt // : Int
-Xlog-implicits
说明隐式不适用的情况。
IntelliJ 有 "show implicits".