You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is invariant generics. LineDataSet is LineDataSet<EntryFloat>, so entries expects MutableList<EntryFloat>. Even though EntryDouble : EntryFloat, MutableList<EntryDouble> is not a MutableList<EntryFloat> because MutableList is invariant (it's both a producer and consumer).
MutableList<T> is invariant in T because it both reads (get() → T) and writes (add(T)). Even though EntryDouble : EntryFloat, the compiler must reject the assignment to prevent this kind of unsound write:
val list: MutableList<EntryFloat> = values // if allowed...
list.add(EntryFloat(1f, 2f)) // would corrupt the original EntryDouble list!
The @Suppress("UNCHECKED_CAST") cast is safe here because:
* JVM erases generics at runtime — both are just MutableList on the heap
* LineDataSet only reads entries from the list as EntryFloat, and EntryDouble IS a EntryFloat
* Nothing writes a plain EntryFloat back into the list through DataSet
0 commit comments