https://kotlinlang.org logo
Title
m

Mike R

07/20/2019, 10:10 PM
So I'm a bit confused about generics. I have an interface like this:
interface IterableResponse {

    val data: List<T>
    val paginationInfo: More?
}
and I am getting an error "Unresolved reference T". I would like for any class that implements the interface to have a
data
property that is a list of anything - but I don't want to use
List<Any>
because I need the implementing classes to have typed Lists. Am I using generics incorrectly? What am I doing wrong?
k

Kevin Luke

07/20/2019, 10:38 PM
You need to pass T in your interface:
interface IterableResponse<T> {

    val data: List<T>
    val paginationInfo: More?
}
m

Mike R

07/20/2019, 11:26 PM
Ahh, got it. Thank you 🙂
h

Hullaballoonatic

07/21/2019, 12:12 AM
Type Parameters get hard to keep track of in a hurry. Feel free to DM me if you have further questions
👍 1
m

Mike R

07/21/2019, 4:30 PM
Thanks @Hullaballoonatic, I appreciate it!