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 - Kotlin Tutorial
From the course: Kotlin Essential Training: Object-Oriented and Async Code
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
-
-
-
Classes19m 32s
-
(Locked)
Interfaces12m 29s
-
(Locked)
Enum classes12m 13s
-
(Locked)
Data classes11m 47s
-
(Locked)
Object classes7m 9s
-
(Locked)
Sealed classes11m 42s
-
(Locked)
Companion objects6m 45s
-
(Locked)
Challenge: Create a Result type using a sealed class1m 45s
-
(Locked)
Solution: Create a Result type using a sealed class6m 13s
-
-
-
-