Jakub
01/09/2020, 5:19 PMval items: Set<Any>
that contains different types including EventItem
. I wanna find in my set the index of EventItem
with the specific date like:
val event = state.items
.filterIsInstance(EventItem::class.java)
.find { it.start == date.atStartOfDay() }
val index = state.items.indexOf(event)
However, it gives me Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.
What’s missing?streetsofboston
01/09/2020, 5:40 PMevent
is of type EventItem?
., a nullable type.
This will have a successful type-inference:
val index = state.items.indexOf(event!!)
streetsofboston
01/09/2020, 5:41 PMitems
type:
val items: Set<Any?>
StavFX
01/09/2020, 7:32 PMval index = state.items
.filterIsInstance<EventItem>()
.indexOfFirst { it.start == date.atStartOfDay() }
// index is potentially -1 (not found) in this implementation
Hitender Pannu
01/10/2020, 7:44 AMStavFX
01/10/2020, 5:18 PM