Java   View all facts   Glossary   Help
mechanism > casting > casting a primitive type
Next castingcasting an object    Upcasting

casting a primitive type
subjectfact 
casting a primitive typecannot be used to convert a primitive type to an objectadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:17.0
has example
//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
added by: JK, source: On To Java, 2001-10-19 11:36:17.0
has syntax (typename)valueadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:17.0
is a subtopic of Objects2001-10-19 11:36:17.0
is a kind of casting2001-10-19 11:36:17.0
may be done implicitly if the destination type is larger than the source type (such as using a byte as an int)added by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:17.0
may not involve a Boolean typeadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:17.0
must be done explicitly if the destination type is smaller than the source type to avoid loss of precisionadded by: JK, source: Teach Yourself Java 2 in 21 Days, 2001-10-19 11:36:17.0
castinghas purpose to convert an instance of one data type into another which is a subclass of the original type2001-10-19 11:36:17.0