Hello, I need an advice. I'm trying to implement a...
# android
r
Hello, I need an advice. I'm trying to implement a clean RecyclerView Adapter for multiple view types. This is as close as I can get but I can't get rid of that @Suppress annotation (or a Lint warning). Do you have any suggestion on how to clean this up even more?
g
You cannot really get rid of it without suppression, because RecyclerView adapter in your case has in and out variance. You can for example check Kotlin Collection interface declaration that has
out
variance, but because also has methods like containsAll which require
in
variance suppress it
See more info about generics here https://kotlinlang.org/docs/reference/generics.html
there are also a few nice articles about this topic
r
Yeah, I read that and came to the came conclusion. I was hoping I missed some detail or that somebody knows of a nice workaround. 😉
d
FirstViewHolder and SecondViewHolder should extend SomeBaseViewHolder and you dont need the cast
g
FirstViewHolder and SecondViewHolder already extend SomeBaseViewHolder
👍 1
Problem not with it, but with type T of SomeBaseViewHolder
d
ahh yes, didnt see the code of the viewholders sorry