未解决的参考:使用Kotlin的Eclipse中的pow [英] Unresolved reference: pow in Eclipse using Kotlin
问题描述
我正在尝试用Kotlin写一些小东西,但是在找到Double
数字的二次幂时遇到了问题.
I'm trying to write something small in Kotlin and I'm having problems with finding the second power of a Double
number.
根据此,Double
应该实现接收另一个Double
的pow
函数,但是当我尝试使用此方法时,我得到了Unresolved reference: pow
和一个错误.
According to this, Double
should implement a pow
function receiving another Double
, but when I try using this method I get Unresolved reference: pow
and an error.
这是我的示例代码:
fun main()
{
val d: Double = 1.1;
val d2: Double = d.pow(2.0); // Here's the error, on the token 'pow'.
println(d2);
}
我找不到任何原因.此功能仅来自Kotlin 1.2,但是Eclipse Installation Details中的Kotlin记录显示Kotlin language support for Kotlin 1.2.50
.
I can't find any reason to this. This feature is only from Kotlin 1.2, but the Kotlin record in the Eclipse Installation Details says Kotlin language support for Kotlin 1.2.50
.
我在更新Kotlin插件之前创建了该项目,并且该项目可能是针对1.2之前的Kotlin版本创建的,但是我在任何地方的设置中都找不到更改已配置的Kotlin版本的信息,因此我假设使用的版本是该版本.已安装,即1.2.50.
I created the project before I updated the Kotlin plugin and it's possible the project was created for Kotlin version before 1.2 but I can't find in the settings anywhere to change the configured Kotlin version so I assume the used version is the one installed i.e. 1.2.50.
顺便说一句,Eclipse所显示的错误图标是灯泡1的错误,表明存在可用的解决方案,但是当我单击该图标时,却没有任何显示,这很奇怪.
By the way, the error icon Eclipse presents is the error with light bulb one, suggesting available solutions exist, but none show up when I click the icon, which is weird.
如果有人可以提出任何理由,那就太好了.
预先感谢.
If anyone could suggest any reason for this, it would be great.
Thanks in advance.
推荐答案
您需要将函数pow
导入文件:
You need to import the function pow
into your file:
import kotlin.math.*
我的完整代码:
import kotlin.math.pow
fun main(args: Array<String>)
{
val d: Double = 1.1;
val d2: Double = d.pow(2.0); // Here's the error, on the token 'pow'.
println(d2);
}
这篇关于未解决的参考:使用Kotlin的Eclipse中的pow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!