The only form of casting originally available was static casting. Which means the casting type needs to be known at compile time. For example, let’s imagine a method that accepts a Stream<Object> , filters all element of a certain type and returns those elements in the right type. This is an example of the usage:

List <?> items = ... List < Date > dates = filter ( Date . class , items );

There’s no way to implement the filter method with static casting. There are actually two issues:

The instanceof operator requires a type, not a Class instance e.g. item instanceof Date The cast syntax as well e.g. (Date) item

The instanceof operator can be replaced with a call to Class.isInstance(Object) (since JDK 1.1). This is quite well-known, if not widely used.

The API to replace the cast syntax, however, is much more "recent". There’s a Class.cast(Object) method since JDK 1.5 It is a simple wrapper around the legacy syntax.

Using both methods, it’s finally possible to implement the filter method above.

static < T > List < T > filter ( Class < T > clazz , List <?> items ) { return items . stream () . filter ( clazz: : isInstance ) . map ( clazz: : cast ) . collect ( Collectors . toList ()); }