我正在尝试用 Kotlin 编写一些小东西,但在查找 Double
数字的二次方时遇到问题。
根据this , Double
应该实现一个 pow
函数接收另一个 Double
,但是当我尝试使用此方法时,我得到 Unresolved reference: pow
和一个错误。
这是我的示例代码:
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
。
我在更新 Kotlin 插件之前创建了该项目,该项目可能是为 1.2 之前的 Kotlin 版本创建的,但我在设置中找不到任何地方可以更改配置的 Kotlin 版本,所以我假设使用的版本是这个版本已安装,即 1.2.50。
顺便说一句,Eclipse 呈现的错误图标是灯泡一的错误,表明存在可用的解决方案,但当我单击该图标时没有显示任何解决方案,这很奇怪。
如果有人能提出任何理由,那就太好了。
提前致谢。
最佳答案
您需要将函数pow
导入到您的文件中:
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);
}
关于eclipse - 未解析的引用 : pow in Eclipse using Kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51149551/