Java - Cast


Cast is a coercion function.

The cast method of Class is the dynamic analog of Java's cast operator.

It casts an object to the class or interface represented by the Class object.

It simply checks that its argument is an instance of the type represented by the Class object.

If so, it returns the argument; otherwise it throws a ClassCastException.

If your object implement a type, it can be cast to it


public class Class<T> {
    T cast(Object obj);

Documentation / Reference

Powered by ComboStrap