What's wrong with ```if (list is ObservableList&lt...
# announcements
j
What's wrong with
Copy code
if (list is ObservableList<Course>)
? it's displaying this error "Cannot check for instace of erased type: ObservableList<Course>"
c
the
<Course>
part does not exist at runtime, due to JVM's generic type erasure, so the
is
check is not possible.
j
Is there a workaround or something? @Czar
c
this isn't very pretty nor do i like it much but you can call some non-mutator method that returns an object inside of that list and check the type of that
so for instance,
if(list.get(index=0) is Course)
c
Note if you check first element, you're out of luck if your list can be empty You could also use a wrapper (also not very pretty)
Copy code
class ObservableListOfCourse(val value: ObservableList<Course>)

if (listWrapper is ObservableListOfCourse)
c
it's an observable list, of course XD
😄 2
^ a bad pun sorry
c
But more often then not you can refactor it so that you don't need an
is
check.
c
yep
c
c
If you only need to check the list type, I believe you can use
is ObservableList<*>
j
@Caleb Allen I need to check list items type also