filterIsInstanceView

Returns a view of this containing all elements that are of the type T.

Stream equivalent: stream.filter(type::isInstance).map(type::cast). This does perform a little more work than necessary, so another option is to insert an unchecked cast at some later point:

@Suppress("UNCHECKED_CAST")
val result: List<String> = stream.filter(String::class::isInstance).toList() as List<String>

See also


Returns a view of this containing all elements that are of the type T.

See also