scala:跟踪隐含选择和其他代码魔法 [英] scala: tracing implicits selection and other code magics

查看:38
本文介绍了scala:跟踪隐含选择和其他代码魔法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图弄清楚库的工作原理时,隐式转换令人困惑.例如,看一个像 'val foo: Foo = 1' 这样的表达式,什么将 1 转换为 Foo?

When trying to figure how a library works, implicit conversions are confusing. For example, looking at an expression like 'val foo: Foo = 1', what converts 1 to Foo?

是否可以指示 Scala 库(或 REPL)打印出在评估表达式时正在执行的代码路径?

Is it possible to instruct the scala library (or REPL) to print out the code paths that are executing while evaluating an expression?

推荐答案

您可以在编译器命令行中添加-Xprint:typer"(或为 Swing GUI 浏览器添加-Ybrowse:typer")以查看代码显式应用的转换.

You can add "-Xprint:typer" to the compiler command line (or "-Ybrowse:typer" for a swing GUI browser) to see the code with the conversions explicitly applied.

这篇关于scala:跟踪隐含选择和其他代码魔法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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