Section numbers ( in bold )
refer to The Java Language Specification,
Version 1.0 July 5, 1996; Draft 5.1.
Kinds of Types. Types are compile time determinable.
-
4.2 Primitive Types
-
4.3 Reference Types
- Class Type
- Interface Type
- Array Type
- Null Type
5.1 Kinds of Conversion
-
5.1.1 Identity Conversion
Boolean Primitive type allows only this Conversion.
-
Widening Conversion: compile time
- 5.1.2 Primitive
- 5.1.4 Reference
-
Narrowing Conversion: run time.
- 5.1.3 Primitive
- 5.1.5 Reference
-
5.1.6 String Conversion
There is a string conversion to type String from every
other type, including the null type.
Map of primitive widening/narrowing. To widen, go up,
to narrow, either go down or the 4 sideways avenues
between char and short or byte. There are 19 widening
and 23 narrowing conversions depicted here.
double
|
float
|
long
|
int
|
/ \
/ \
/ +->short
char<-+ |
+-> byte
Conversion contexts.
- Assignment
- Method invocation
- Casting
- String
- Numeric promotion
Type of a variable.
- 4.5.1 Primitive. Then the run time and compile time
type always agree.
- 4.5.2 Reference. Then the run time type is a reference
to an object which has a class, which might not be
the same class as the compile time type of the variable.
4.5.5 Variables have types, Objects have Classes.
4.5.3 Kinds of Variables.
-
Local
-
Instance
-
Class
-
Method parameters
-
Constructor parameters
-
Array components
-
Exception-handling parameter