lorenzo
lorenzo

Reputation: 1743

Kotlin generics cast unchecked warning

I have this piece of code

inline fun <reified T>store(dataList: List<T>) {
            when (T::class.java) {
                MyClass::class.java -> this.sasses = dataList as List<MyClass>

The as List<MyClass> issues a warning:

Unchecked cast: List to List

I'm pretty sure my code is safe but how to silence this warning?

Thanks!

Upvotes: 0

Views: 83

Answers (1)

Jakir Hossain
Jakir Hossain

Reputation: 3930

Use filterIsInstance to avoid this warning. like

inline fun <reified T>store(dataList: List<T>) {
            when (T::class.java) {
                MyClass::class.java -> this.sasses = dataList.filterIsInstance<MyClass>()

Upvotes: 1

Related Questions