Data Types Flashcards
Wrappers
All the wrapper objects are immutable. So when you do obj++, what actually happens is something like this:
obj = new Integer( obj.intValue() + 1);
!!!!!!!!!!!!!!!!!!!!
Boxing
Boxing:
primitive–> Wrapper
AutBoxing: invers
Narrowing
An implicit narrowing primitive conversion may be used if all of the following conditions are satisfied:
- The expression is a compile time constant expression of type byte, char, short, or int.
- The type of the variable is byte, short, or char.
- The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable.
Note that implicit narrowing conversion does not apply to long or double. So, char ch = 30L; will fail even though 30 is representable in char.
***boolean cannot be converted to any other types!!!!!
EG:
short s = 12 ;–> This is valid since 12 can fit into a short and an implicit narrowing conversion can occur.
long g = 012–> 012 is a valid octal number
float f = -123;–> Implicit widening conversion will occur in this case
float d = 0 * 1.5;–>double cannot be implicitly narrowed to a float even though the value is representable by a float.
float d = 0 * 1.5f; and float d = 0 * (float)1.5 ; are OK