August 2017
Intermediate to advanced
440 pages
10h
English
Kotlin interfaces are similar to Java 8 interfaces and different to interfaces in previous version Java. An interface is defined using the interface keyword. Let's define an EmailProvider interface:
interface EmailProvider {
fun validateEmail()
}
To implement the preceding interface in Kotlin, use the same syntax as for extending classes--a single colon character (:). There is no implements keyword, in contrast to Java:
class User:EmailProvider {
override fun validateEmail() {
//email validation
}
}
The question of how to extend a class may arise and implement an interface at the same time. Simply place the class name after the colon, and use a comma to add one or more interfaces. It's not required to place the superclass in ...
Read now
Unlock full access