Function should have 'operator' modifier
Reports a function that matches one of the operator conventions but lacks the operator
keyword.
By adding the operator
modifier, you might allow function consumers to write idiomatic Kotlin code.
Example:
class Complex(val real: Double, val imaginary: Double) {
fun plus(other: Complex) =
Complex(real + other.real, imaginary + other.imaginary)
}
fun usage(a: Complex, b: Complex) {
a.plus(b)
}
The quick-fix adds the operator
modifier keyword:
class Complex(val real: Double, val imaginary: Double) {
operator fun plus(other: Complex) =
Complex(real + other.real, imaginary + other.imaginary)
}
fun usage(a: Complex, b: Complex) {
a + b
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Kotlin, @snapshot@ |
Last modified: 13 July 2023