当我尝试执行以下代码时:
fun main(args: Array<String>) {
val x = BigInteger.ONE
var y = BigInteger.TEN
val z = x + y;
}
我收到这个错误,出了什么问题?我正在使用1.0.0-beta-1038-IJ143-19
Error:(7, 15) Kotlin: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun <T> kotlin.Array<???>.plus(array: kotlin.Array<out ???>): kotlin.Array<???> defined in kotlin
public operator fun <T> kotlin.Array<???>.plus(collection: kotlin.Collection<???>): kotlin.Array<???> defined in kotlin
public operator fun <T> kotlin.Array<java.math.BigInteger!>.plus(element: java.math.BigInteger!): kotlin.Array<java.math.BigInteger!> defined in kotlin
public operator fun kotlin.BooleanArray.plus(element: kotlin.Boolean): kotlin.BooleanArray defined in kotlin
public operator fun kotlin.BooleanArray.plus(array: kotlin.BooleanArray): kotlin.BooleanArray defined in kotlin
public operator fun kotlin.BooleanArray.plus(collection: kotlin.Collection<kotlin.Boolean>): kotlin.BooleanArray defined in kotlin
public operator fun kotlin.ByteArray.plus(element: kotlin.Byte): kotlin.ByteArray defined in kotlin
public operator fun kotlin.ByteArray.plus(array: kotlin.ByteArray): kotlin.ByteArray defined in kotlin
public operator fun kotlin.ByteArray.plus(collection: kotlin.Collection<kotlin.Byte>): kotlin.ByteArray defined in kotlin
public operator fun kotlin.Char.plus(string: kotlin.String): kotlin.String defined in kotlin
public operator fun kotlin.CharArray.plus(element: kotlin.Char): kotlin.CharArray defined in kotlin
public operator fun kotlin.CharArray.plus(array: kotlin.CharArray): kotlin.CharArray defined in kotlin
public operator fun kotlin.CharArray.plus(collection: kotlin.Collection<kotlin.Char>): kotlin.CharArray defined in kotlin
public operator fun <T> kotlin.Collection<???>.plus(array: kotlin.Array<out ???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Collection<???>.plus(collection: kotlin.Iterable<???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Collection<???>.plus(sequence: kotlin.Sequence<???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Collection<java.math.BigInteger!>.plus(element: java.math.BigInteger!): kotlin.List<java.math.BigInteger!> defined in kotlin
public operator fun kotlin.DoubleArray.plus(collection: kotlin.Collection<kotlin.Double>): kotlin.DoubleArray defined in kotlin
public operator fun kotlin.DoubleArray.plus(element: kotlin.Double): kotlin.DoubleArray defined in kotlin
public operator fun kotlin.DoubleArray.plus(array: kotlin.DoubleArray): kotlin.DoubleArray defined in kotlin
public operator fun kotlin.FloatArray.plus(collection: kotlin.Collection<kotlin.Float>): kotlin.FloatArray defined in kotlin
public operator fun kotlin.FloatArray.plus(element: kotlin.Float): kotlin.FloatArray defined in kotlin
public operator fun kotlin.FloatArray.plus(array: kotlin.FloatArray): kotlin.FloatArray defined in kotlin
public operator fun kotlin.IntArray.plus(collection: kotlin.Collection<kotlin.Int>): kotlin.IntArray defined in kotlin
public operator fun kotlin.IntArray.plus(element: kotlin.Int): kotlin.IntArray defined in kotlin
public operator fun kotlin.IntArray.plus(array: kotlin.IntArray): kotlin.IntArray defined in kotlin
public operator fun <T> kotlin.Iterable<???>.plus(array: kotlin.Array<out ???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Iterable<???>.plus(collection: kotlin.Iterable<???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Iterable<???>.plus(sequence: kotlin.Sequence<???>): kotlin.List<???> defined in kotlin
public operator fun <T> kotlin.Iterable<java.math.BigInteger!>.plus(element: java.math.BigInteger!): kotlin.List<java.math.BigInteger!> defined in kotlin
public operator fun kotlin.LongArray.plus(collection: kotlin.Collection<kotlin.Long>): kotlin.LongArray defined in kotlin
public operator fun kotlin.LongArray.plus(element: kotlin.Long): kotlin.LongArray defined in kotlin
public operator fun kotlin.LongArray.plus(array: kotlin.LongArray): kotlin.LongArray defined in kotlin
public operator fun <K, V> kotlin.Map<???, ???>.plus(pairs: kotlin.Array<kotlin.Pair<???, ???>>): kotlin.Map<???, ???> defined in kotlin
public operator fun <K, V> kotlin.Map<???, ???>.plus(pairs: kotlin.Iterable<kotlin.Pair<???, ???>>): kotlin.Map<???, ???> defined in kotlin
public operator fun <K, V> kotlin.Map<???, ???>.plus(map: kotlin.Map<???, ???>): kotlin.Map<???, ???> defined in kotlin
public operator fun <K, V> kotlin.Map<???, ???>.plus(pair: kotlin.Pair<???, ???>): kotlin.Map<???, ???> defined in kotlin
public operator fun <K, V> kotlin.Map<???, ???>.plus(pairs: kotlin.Sequence<kotlin.Pair<???, ???>>): kotlin.Map<???, ???> defined in kotlin
public operator fun <T> kotlin.Sequence<???>.plus(array: kotlin.Array<out ???>): kotlin.Sequence<???> defined in kotlin
public operator fun <T> kotlin.Sequence<???>.plus(collection: kotlin.Iterable<???>): kotlin.Sequence<???> defined in kotlin
public operator fun <T> kotlin.Sequence<???>.plus(sequence: kotlin.Sequence<???>): kotlin.Sequence<???> defined in kotlin
public operator fun <T> kotlin.Sequence<java.math.BigInteger!>.plus(element: java.math.BigInteger!): kotlin.Sequence<java.math.BigInteger!> defined in kotlin
public operator fun <T> kotlin.Set<???>.plus(array: kotlin.Array<out ???>): kotlin.Set<???> defined in kotlin
public operator fun <T> kotlin.Set<???>.plus(collection: kotlin.Iterable<???>): kotlin.Set<???> defined in kotlin
public operator fun <T> kotlin.Set<???>.plus(sequence: kotlin.Sequence<???>): kotlin.Set<???> defined in kotlin
public operator fun <T> kotlin.Set<java.math.BigInteger!>.plus(element: java.math.BigInteger!): kotlin.Set<java.math.BigInteger!> defined in kotlin
public operator fun kotlin.ShortArray.plus(collection: kotlin.Collection<kotlin.Short>): kotlin.ShortArray defined in kotlin
public operator fun kotlin.ShortArray.plus(element: kotlin.Short): kotlin.ShortArray defined in kotlin
public operator fun kotlin.ShortArray.plus(array: kotlin.ShortArray): kotlin.ShortArray defined in kotlin
public operator fun kotlin.String?.plus(other: kotlin.Any?): kotlin.String defined in kotlin
答案 0 :(得分:3)
无法解析加号操作员http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.math/-big-integer/plus.html
添加导入会修复它:import kotlin.math.*
至于奇怪的行为,有两个问题:
1)是否应该默认导入?如果是这样,那就是一个错误
2)IDEA是否表示有意自动导入?如果它没有,那就是一个错误。
无论哪种方式,请将其报告给https://youtrack.jetbrains.com/issues/KT
答案 1 :(得分:2)
Kotlin导入是隐含的,不需要添加。通常这样的错误是当您的插件版本是Kotlin的一个版本时,您的项目中的IntelliJ IDEA缓存或库版本是另一个版本。您的IDE中可能有另一条错误消息,告诉您Kotlin库与插件版本不匹配。发生这种情况时,请检查:
Kotlin的IDE插件版本与项目使用的库相同(现在Kotlin Betas不太重要,可以更加一致地保持二进制兼容性)
在IDE中清除缓存,您可以在IntelliJ IDEA中找到“文件 - &gt; Invalidate Caches and Restart”菜单项,然后选择该选项并重新启动。
您实际上在类路径中有Kotlin运行时JAR。
此问题没有错误。这是上述问题之一。