Specifications
Sun Services
Java™ Programming Language
Module 4, slide 16 of 31
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Casting
• If information might be lost in an assignment, the
programmer must confirm the assignment with a cast.
• The assignment between long and int requires an
explicit cast.
long bigValue = 99L;
int squashed = bigValue; // Wrong, needs a cast
int squashed = (int) bigValue; // OK
int squashed = 99L; // Wrong, needs a cast
int squashed = (int) 99L; // OK, but...
int squashed = 99; // default integer literal










