From the course: Moving Your iOS App to Android Using Kotlin

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Generics

Generics

- [Instructor] Let's go ahead and dive into our generics example. First, we'll come up here and comment out this, collapse the monitor and then, let's go into our generics KT class and in here, we're going to have a few things. We'll just make our first generic. They're very similar to Swift, box<T> where T is of type T, var value = t. You've probably seen this before in Swift, it's a very powerful paradigm to work with. We'll go ahead and surround this and we'll say this is generic types. But that's how we would create a simple generic. There's a larger discussion to talk about variants, co-variants, contra-variants, in-variants, it is just a concept that works with most objects like if we chose a string, we know that a string is a descendant of object or in Kotlin, it's a descendant of any and lists of objects aren't necessarily the same as lists of strings, so you can't assign a variable of a list of object to a list of strings. It's a lot of more complex thought going into it and…

Contents