I have something like this in the code
var barCode: BarCode? = null
now getBarCode() is defined in the interface - then I get the error that this might be an accidental override. unfortunately this does not work:
var barCode: BarCode? = null
override get
I could do something like this:
private var barCode: BarCode? = null
override fun getBarCode(): BarCode? = barCode
fun setBarCode(barCode: BarCode) {
this.barCode = barCode
}
but this looks like way to many likes and verbosity for kotlin - there must be a shorter way - especially as this pattern will repeat multiple times in this class
As of Kotlin 1.0, there is no shorter way: a method getBarCode()
in a Java interface needs to be implemented by a method named getBarCode()
in Kotlin, not by a property named barCode
.
There's an issue requesting to make it possible to override Java methods with properties; you can vote for it to get notifications of updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With