查找所有隐式 [英] Find all implicits

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

问题描述

Scala 有没有办法在我的代码中查找和显示隐式的所有用法,或者在不启用隐式的情况下进行编译(所以我得到编译错误)?我希望找出我无意中在内部循环中分配额外内存的地方.

Is there a way in Scala to find and display all uses of implicits in my code, or compile without implicits enabled (so I get compilation errors)? I'm hoping to identify places where I'm unintentionally allocating extra memory in inner loops.

推荐答案

您可以使用 -Xprint:typer 选项并查看如何检查感兴趣的内部循环的类型.隐式调用将出现在打印的源代码中.您可能需要将输出通过管道传输到文件,以便您可以搜索感兴趣的部分.

You can use -Xprint:typer option and look at how the inner loops of interest are typed checked. The implicit calls will appear in the printed source code. You may need to pipe the output to a file so that you can search for the interesting sections.

还有位于 http://scala-ide.org/download/nightly 的 Scala Eclipse IDE nightlies.html 具有显示隐式功能.您必须在 PreferencesScalaImplicits 部分启用它.

Also the Scala Eclipse IDE nightlies at http://scala-ide.org/download/nightly.html have a display implicit feature. You have to enable it in the Preferences, Scala, Implicits section.

左边距的双箭头表示使用了隐式:

The double arrows on the left margin shows that an implicit is used:

悬停时,显示详细信息:

On hover, it shows the details:

IDEA scala 插件也可以显示带下划线的隐式转换,参见同一段代码:

The IDEA scala plugin can also show implicit conversions with underline, see the same piece of code:

它还应该显示使用 CTRL-SHIFT-Q 快捷方式使用了哪个,但我用它不太成功...

It should also show which one is used using the CTRL-SHIFT-Q shortcut, but I had less success with it...

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

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