From the course: Kotlin Essential Training: Object-Oriented and Async Code

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Interfaces

Interfaces

- [Instructor] Interfaces allow us to define reusable type contracts to be implemented by other classes, objects, and even interfaces. We're going to explore how to define an interface, how to define methods and properties on that interface, and finally, we'll see how to provide default implementations for interface methods. Now let's define our first interface in Kotlin. We're going to do this within our main.KT file here. We could also do this in another file but for now we'll keep it all in one file just to keep it simple. So to define a basic interface, we start by typing the interface keyword and then the name of the interface. So in this case, we're going to call our interface string provider. At the moment, This interface has no methods or properties but it could still be implemented by other types and we could check if a variable is an instance of strength provider by using the is keyword. So for example, if we…

Contents