i have a marker interface ```interface RoomModel`...
# android
l
i have a marker interface
Copy code
interface RoomModel
and an entity that implements this interface
Copy code
@Entity(tableName = "ContentAuthorModule")
ContentAuthorModule : RoomModel {}
now if i have a
Copy code
List<RoomModel>
how do i check if its a
Copy code
List<ContentAuthorModule>
I tried to do
Copy code
roomModels is List<ContentAuthorModule>
Copy code
override fun saveRoomModels(roomModels: List<RoomModel>) {
    when(roomModels) {
        is List<ContentAuthorModule> ->
            contentAuthorModuleDao.insertAll(roomModels)
    }
}
but it gives my a syntax error that says
Copy code
Cannot check for instance of erased type : List<ContentAuthorModule>
is there another way to do this?
a
You can use
roomModels.filterIsInstance<ContentAuthorModule>()
which will return a list of type
List<ContentAuthorModule>
👍 2
You can't do an
is
because List is a generic, so during runtime the types are erased.
💯 1