https://kotlinlang.org logo
Title
e

elect

03/09/2018, 7:26 PM
I found myself implementing various methods instead
var
with custom get and set methods because they are in an interface.. isn't there any other way?
c

christopher

03/09/2018, 7:28 PM
You don’t want to do this?
interface Foo {
    var foo: String
        get() = ""
        set(value) {}
}
e

elect

03/09/2018, 7:30 PM
I recall I tried that and it was complaining
a

Andreas Sinz

03/09/2018, 7:30 PM
If its a java interface, you are out of luck
e

elect

03/09/2018, 7:30 PM
thanks
I expect in java to be translated as
get*
and
set*
, or?
c

christopher

03/09/2018, 7:30 PM
You have to define the getter, because otherwise it tries to have a backing field, which it can’t in an interface.
👍 2
a

Andreas Sinz

03/09/2018, 7:31 PM
yes, but overriding a
get*
with a property gets very tricky in mixed inheritance architectures
e

elect

03/09/2018, 7:31 PM
uhm, so better stay with the classical approach?
c

christopher

03/09/2018, 7:57 PM
If you can’t overload the get and set methods in java (which I haven’t tried), and that’s something you need. then yes, I would say you’re stuck with having actual get and set methods in Kotlin.
e

elect

03/09/2018, 7:57 PM
ok
thanks
a

Andreas Sinz

03/09/2018, 8:11 PM
e

elect

03/09/2018, 8:11 PM
smart, I almost forgot about the possibility to rename them