Cast Operator

Purpose:

Casting changes the type of a reference to an object.

Mechanics:

<variable name 1> = (<new type>)<variable name 2>;

Example:

myFloat = (int)myInt;

Usage:

  • While casting does nothing to the object itself, it changes its type.

Restrictions:

If the cast is not valid, a ClassCastException is thrown.
Back to the Table of Contents
email suggestions to: cs015tas@cs.brown.edu