Java View all facts Glossary Help |
mechanism > casting |
casting comparison table |
Subject | use | have example | have syntax | done | involve | perform |
---|---|---|---|---|---|---|
casting a primitive type | to convert a primitive type to an object | //i is an int | (typename)value | explicitly if the destination type is smaller than the source type to avoid loss of precision | a Boolean type | |
casting an object | to convert an object to a primitive type - use a wrapper class instead | (String)i.next() | (classname)object | explicitly 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 mechanism: garbage collection Up: mechanism Previous mechanism: binding