https://kotlinlang.org logo
Title
d

Dalinar

09/05/2017, 9:49 AM
is there a way to override a java property with a kotlin property declaration? or must the separate getter and setters always be overriden separately?
d

dragas

09/05/2017, 10:01 AM
Properties can't be overriden in java. See https://docs.oracle.com/javase/8/docs/api/java/lang/Override.html. But if you really want pure fields, use
@JvmField
annotation.
Meanwhile, kotlin properties already generate setters and getters for them, thus all you need is an
override
modifier.
d

Dalinar

09/05/2017, 12:35 PM
I wonder if it is not possible in kotlin to override as a property when the setter is in one java interface and the getter in another in java but the kotlin class implements the setter interface (which itself in java implements the getter interface).. this might be why i'm having problems
I did it that way because I wanted one interface read-only, but the other writeable
I'll try porting the java interfaces to kotlin making one val and the other overriding with var and using JVmfield, hopefully that'll work
k

karelpeeters

09/05/2017, 3:52 PM
You can't override getters and setters with a property in Kotlin, see https://youtrack.jetbrains.com/issueMobile/KT-6653