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

yoavst

08/13/2017, 5:51 PM
I have a java class with:
Copy code
protected X event;
public Y getEvent()
How do I call them from Kotlin (extending the class)?
s

supaham

08/13/2017, 5:52 PM
classInstance.event
If you mean to access the field, I'm pretty sure the only way would be to rename the field to something like
_event
y

yoavst

08/13/2017, 5:53 PM
Overload resolution ambiguity
s

supaham

08/13/2017, 5:53 PM
yeah, i've never come across this scenario before. If this is from a library, I'd guess there's a work around for it.
y

yoavst

08/13/2017, 5:54 PM
I'm doing a presentation about Kotlin for the company, and I want to convert some of the code for a showcase. I guess I'll have to rename the field.
f

fitzoh

08/13/2017, 8:17 PM
Have you tried having intellij convert the code?
y

yoavst

08/13/2017, 8:24 PM
I've renamed it but it would have been impossible to keep the original class Java .
f

fitzoh

08/13/2017, 9:06 PM
Copy code
open class BaseClass {
    protected var event: Int = 0

    fun getEvent(): String {
        return event.toString()
    }
}


class SubClass : BaseClass() {
    val fromSuperClass: Int
        get() = event
}
y

yoavst

08/14/2017, 6:25 AM
Yes that would work but not if you keep the original class Java
2 Views