Section numbers ( in bold )
refer to The Java Language Specification,
Version 1.0 July 5, 1996; Draft 5.1.
Remember:
4.5.5 Variables have types, Objects have Classes.
Kinds of Types. Types are compile time determinable.
-
4.2 Primitive Types
-
4.3 Reference Types
- Class Type
- Interface Type
- Array Type
Objects have a Class, and that class might implement an interface.
An object implementing an interface can be assigned to a variable of the
interface's type.
Arrays extend Object. They have a field length
of type
int
which gives the number of elements in the array.
The length can be zero, which is the empty array, distinct from
an array variable of value null
.
5.1 Kinds of Conversion
-
5.1.1 Identity Conversion
Boolean Primitive type allows only this Conversion.
-
Widening Conversion:
- 5.1.2 Primitive (run time)
- 5.1.4 Reference (compile time)
-
Narrowing Conversion:
- 5.1.3 Primitive (run time)
- 5.1.5 Reference (run time)
-
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