https://kotlinlang.org logo
#announcements
Title
# announcements
w

wasyl

07/13/2017, 9:03 AM
Is it possible to have a property override Java interface method? As in
String getName()
in interface would be implemented by
val name: String
property. I get
same JVM signature
error, although this SO answer suggests that having the property
private
would solve the problem: https://stackoverflow.com/questions/29268526/how-to-overcome-same-jvm-signature-error-when-implementing-a-java-interface
k

karelpeeters

07/13/2017, 10:38 AM
Don't you need to add
override
to it?
w

wasyl

07/13/2017, 11:47 AM
I tried all combinations
private/[]
and override, nothing worked
k

karelpeeters

07/13/2017, 12:02 PM
Apparently this is indeed not possible, and there is some discussion about this here: https://youtrack.jetbrains.com/issue/KT-6653
👍 1
w

wasyl

07/13/2017, 12:53 PM
That’s right, thanks! SO never ceases to amaze, how is an accepted answer completely wrong ;_;
c

Czar

07/13/2017, 2:18 PM
Copy code
class KtClass(private val name: String) : JInterface {
	override fun getName() = name
}
I use this in my code base, it's kinda hacky to my taste, but it works when I do not have control over the interface/parent.
4 Views