问题
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