tipsy
03/18/2019, 4:03 PMfilter
smart cast ?
connectors.filter { it is ServerConnector }.map { it as ServerConnector } // why is map needed here?
maybe there's a better solution for this?diesieben07
03/18/2019, 4:06 PMfilterIsInstance<ServerConnector>
.streetsofboston
03/18/2019, 4:06 PM{ it is ServerConnector ]
, but a lambda-val or lambda-var….
The compiler cannot guarantee type safety.
Ah… @diesieben07 already posted the answer 🙂tipsy
03/18/2019, 4:11 PMtipsy
03/18/2019, 4:11 PMstreetsofboston
03/18/2019, 4:19 PMfilter
is defined to return the same type as its source type, something like this `fun <T> List<T>.filter(pred: (T) -> Boolean) : List<T>`; the compiler, looking at the signature of filter
, can’t know that T
will be same exact type (upper and lower bound) of all items.gildor
03/18/2019, 4:20 PMtipsy
03/18/2019, 4:28 PMa is b
and cast accordinglytipsy
03/18/2019, 4:28 PMAlexey Belkov [JB]
03/18/2019, 4:29 PMgildor
03/18/2019, 4:35 PMstreetsofboston
03/18/2019, 4:41 PMpredicate: (T) -> Boolean
parameter. Even when inlined, that would be tricky.
And since there is a filterIsInstance
function, it may not be worth the trouble… :)gildor
03/18/2019, 4:53 PMSiebelsTim
03/18/2019, 8:21 PMkirillrakhman
03/19/2019, 8:47 AM