https://kotlinlang.org logo
Title
t

thana

12/01/2021, 11:07 AM
Hi, in a situation like this: https://pl.kotl.in/vK8g6iJtG is there a way to implement this interface while keeping the
username
part of the primary ctor and without changing its name?
j

Joffrey

12/01/2021, 11:16 AM
If the interface is defined in Kotlin, you should instead declare a property instead of a getter, then overriding it is simple:
interface Foo {
    val username: String
}

data class User(override val username: String): Foo
t

thana

12/01/2021, 11:17 AM
unfortunately its defined in java
and not even by me, but by a library
j

Joffrey

12/01/2021, 12:05 PM
Ah if it's Java then it will indeed be a problem, see: https://youtrack.jetbrains.com/issue/KT-6653
t

thana

12/01/2021, 12:29 PM
funny, thats even the very same interface i have problems with 😄
😆 1
thank you 🙂
n

Nick Allen

12/27/2021, 3:13 AM
You could use
@get:JvmName("getUsernameKt")
on the constructor parameter to avoid that conflict with the getUsername override method.
t

thana

12/28/2021, 10:39 AM
@Nick Allen awesome, thank you!