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
}
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
AddOperatorModifier- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Kotlin, 242.22892-IJ |
Last modified: 11 September 2024