Kotlin interfaces are very similar to C#’s (although without the I
naming convention).
Kotlin
interface MyInterface {
val name: String
fun printName()
}
Like C# 8.0, Kotlin methods can have default implementations.
interface MyInterface {
val name: String
fun printName() {
println(name)
}
}
Classes implement interface members with the override
keyword.
class MyClass : MyInterface {
override val name: String = "Bob"
override fun printName() {
// override the default from the interface
}
}