Java   View all facts   Glossary   Help
mechanism > casting
Next mechanismgarbage collection    Upmechanism    Previous mechanismbinding   

casting comparison table
Subject use have example have syntax done involve perform
casting a primitive typeto convert a primitive type to an object
//i is an int
//d is a double
(double) i // a double expression
(int) d // an int expression
// note that the original types of i and d remain the same
(typename)valueexplicitly if the destination type is smaller than the source type to avoid loss of precisiona Boolean type 
casting an objectto convert an object to a primitive type - use a wrapper class instead
(String)i.next()
(classname)objectexplicitly if the destination type is a superclass of the source type if the source and destination types of the object are related by inheritance - one class must be a subclass of the other

Next mechanismgarbage collection    Upmechanism    Previous mechanismbinding