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

poohbar

11/01/2017, 3:36 PM
I have this Kotlin data class:
Copy code
class Person(override val id: String, val name: String) : HasId
and this Java interface:
Copy code
public interface HasId {
    String getId();
}
How do I implement the interface? The above example gives me
'id' overrides nothing
d

diesieben07

11/01/2017, 3:46 PM
You must declare the
id
val as private and implement
getId
using a
fun
. You will still be able to use the
object.id
syntax when accessing the field.
k

karelpeeters

11/01/2017, 4:54 PM
2 Views