Here you can find the source of filterType(Stream stream, Class type)
@SuppressWarnings("unchecked") public static <Sub extends Sup, Sup> Stream<Sub> filterType(Stream<Sup> stream, Class<Sub> type)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.stream.Stream; public class Main { @SuppressWarnings("unchecked") public static <Sub extends Sup, Sup> Stream<Sub> filterType(Stream<Sup> stream, Class<Sub> type) { return (Stream<Sub>) stream.filter(it -> type.isInstance(it)); }/*from w ww .j av a 2 s .c o m*/ public static <Sub extends Sup, Sup> Stream<Sub> filterType(Collection<Sup> collection, Class<Sub> type) { return filterType(collection.stream(), type); } }