Unresolved reference: pow in Eclipse using Kotlin

喜欢而已 提交于 2019-12-24 03:32:07

问题


I'm trying to write something small in Kotlin and I'm having problems with finding the second power of a Double number.

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.

Here's my sample code:

fun main()
{
    val d: Double = 1.1;
    val d2: Double = d.pow(2.0); // Here's the error, on the token 'pow'.
    println(d2);
}

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.

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.

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.


回答1:


You need to import the function pow into your file:

import kotlin.math.*

My full code:

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);
}


来源:https://stackoverflow.com/questions/51149551/unresolved-reference-pow-in-eclipse-using-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!