Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea kotlin cannot auto import some operator function such as +

For example:

Class common.number.Number.kt:

operator fun Int.plus(other: BigInteger): BigInteger {
    return BigInteger(this.toString()).add(other)
}

Class common.test.Test.kt:

var i = 1 + BigInteger("1")

Then the Intellij Idea shows an error in class Test.kt. However, if I add the following import, the error disappears:

import common.number.Number.plus

How can I make IntelliJ Idea import this operator function automatically?

like image 504
wozuiqiangdeaoyi Avatar asked Dec 05 '25 16:12

wozuiqiangdeaoyi


1 Answers

It is need because you make special extension operator. It is working same like extension function. Import required because idea need to know which exactly extension you want using. So extensions can be more then one.

like image 62
Stanley Wintergreen Avatar answered Dec 08 '25 07:12

Stanley Wintergreen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!