There is a special value called null
which is assignable to most types.
void main() {
String name = null;
int[] numbers = null;
System.out.println(name);
System.out.println(numbers);
}
The only types which null
cannot be assigned to are int
, double
, char
, and boolean
.1
void main() {
// Will not work
int x = null;
}
Footnotes
-
As well as
long
,short
,byte
, andfloat
but I haven't shown you those yet. ↩