显示推断的Scala表达式类型 [英] Showing inferred types of Scala expressions

查看:102
本文介绍了显示推断的Scala表达式类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看Scala编译器为表达式等推断的类型?我有一些带有复杂类型推断和隐式转换的代码,仅通过阅读代码就很难知道发生了什么。

How can I see the types inferred by the Scala compiler for expressions etc.? I have some code with complicated type inference and implicit conversions, and it's hard to see what's going on just by reading the code.

我尝试添加

scalacOptions in Compile += "-Xprint-types"

$ b.b

在build.sbt中,但这没有效果。

in build.sbt, but this has no effect.

直接使用scalac并不是很吸引人,因为我有很多依赖项。

Using scalac directly isn't very appealing because I have lots of dependencies.

我使用Eclipse Scala插件和ENSIME编写代码,并使用SBT进行构建。

I use the Eclipse Scala plugin and ENSIME to write code, and SBT to build.

推荐答案

此精确功能已在Eclipse Scala IDE 3.0中添加!

This exact feature has been added in Eclipse Scala IDE 3.0!

选择代码的任意部分,然后按Ctrl-Shift-W T(替换在Mac上按Cmd Ctrl)以查看推断的类型。

Select any portion of code and press Ctrl-Shift-W T (replacing Ctrl by Cmd on Mac) to see the inferred type.

这篇关于显示推断的Scala表达式类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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