Java - Cast

Java Conceptuel Diagram


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

Discover More
Java Conceptuel Diagram
Java - (Generic|Parameterized) type - (Class|Interface|Method) Parametrization

and Integer.class is of type Class Stronger type checks at compile time. Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find. The compiler can check the type...
Java Conceptuel Diagram
Java - Array

in Java. Arrays implement most of the List operations, but not remove and add. They are “fixed-size” Lists. An array is a container object that holds : a fixed number of values of a single...
Java Conceptuel Diagram
Java - List (sequence)

A list (also known as a sequence): is ordered allow duplicates (multiple null elements if they allow them) is zero based. The first element is at the position 0. can contain themselves as elements...

Share this page:
Follow us:
Task Runner