Is it possible to have a property override Java in...
# announcements
w
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
Don't you need to add
override
to it?
w
I tried all combinations
private/[]
and override, nothing worked
k
Apparently this is indeed not possible, and there is some discussion about this here: https://youtrack.jetbrains.com/issue/KT-6653
👍 1
w
That’s right, thanks! SO never ceases to amaze, how is an accepted answer completely wrong ;_;
c
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.