如何找到Scala隐式定义的位置? [英] How to find where Scala implicit is defined?

查看:93
本文介绍了如何找到Scala隐式定义的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法可以接受隐式参数,并且在代码中某处已定义了隐式值.但是我找不到我的代码在其中创建的位置.

I have a method that accepts an implicit parameter and somewhere in the code that implicit value has been defined. However I haven't been able to find where my code has created it.

有没有一种简单的方法来查找Scala中定义了隐式值的位置?到目前为止,我只是在扫描导入的源代码,但这非常繁琐.我正在使用IntelliJ.

Is there an easy way to find where an implicit value has been defined in Scala? So far I'm just scanning the source code of my imports but this is extremely tedious. I am using IntelliJ.

推荐答案

Intellij scala插件最近添加了可显式显示隐式特性的功能:)

Intellij scala plugin has recently added feature to display implicits explicitly :)

您可以按ctl+alt+shift+++键显示隐式内容.

You can press ctl+alt+shift+++ to display implicits.

或参考Travis Brown的答案此处. 他的回答中的小片段:

Or Refer answer from Travis Brown here. Small snippet from his answer :

scala> import scala.reflect.runtime.universe.reify
import scala.reflect.runtime.universe.reify

scala> reify("a" * 3).tree
res6: reflect.runtime.universe.Tree = Predef.augmentString("a").$times(3)

这篇关于如何找到Scala隐式定义的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆