如何在scala中找到隐式函数或变量 [英] how to find the implicit function or variables in scala

查看:158
本文介绍了如何在scala中找到隐式函数或变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到Scala代码中使用的隐式转换或隐式参数值.这使阅读开源项目非常混乱.

I can't find the implicit conversions or implicit argument values being used in Scala code. This makes reading open source projects very confusing.

implicitly技巧只能帮助检查是否存在某种有效的隐式变量,但无法确定隐式变量的定义位置.

The implicitly trick can only help to check if there is a valid implicit variable of some type, but couldn't tell where the implicit variable was defined.

scala> implicitly[(Int) => RichInt]
res2: Int => scala.runtime.RichInt = <function1>

是否有一种简单的方法来找到一段代码正在使用的隐式转换和值的定义?如果源代码文件很长,那将是一个巨大的工作.

Is there an easy way to find the definitions of the implicit conversions and values being used by a piece of code? If the source code file is very long, it will be a huge work.

推荐答案

SO涵盖的一个技巧:

One trick that has been covered on SO:

scala> import reflect.runtime._,universe._
import reflect.runtime._
import universe._

scala> reify { "abc".size }
res1: reflect.runtime.universe.Expr[Int] = Expr[Int](Predef.augmentString("abc").size)

最近的REPL:

scala> 3 until 4 //print<hit tab completion>
   scala.Predef.intWrapper(3).until(4) // : scala.collection.immutable.Range

这篇关于如何在scala中找到隐式函数或变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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