首页 > 解决方案 > 未解决的参考:在 Eclipse 中使用 Kotlin 的 pow

问题描述

我正在尝试在 Kotlin 中编写一些小东西,但在查找Double数字的二次方时遇到了问题。

根据这个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 安装详细信息中的 Kotlin 记录说Kotlin language support for Kotlin 1.2.50

我在更新 Kotlin 插件之前创建了该项目,并且该项目可能是为 1.2 之前的 Kotlin 版本创建的,但我无法在任何地方的设置中找到更改配置的 Kotlin 版本,所以我假设使用的版本是已安装的版本,即 1.2 .50。

顺便说一句,Eclipse 显示的错误图标是灯泡一的错误,表明存在可用的解决方案,但是当我单击该图标时没有显示,这很奇怪。

如果有人可以为此提出任何理由,那就太好了。
提前致谢。

标签: eclipsemathkotlinpow

解决方案


您需要将该函数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);
}

推荐阅读