null typeって何

概要

null typeをちゃんと読む

仕様

Java言語仕様にはnull typeがあります。

There is also a special null type, the type of the expression null (§3.10.7, §15.8.1), which has no name.

http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.1

特別なnull type、すなわちnullという式の型がありますが、名前はありません。

The null reference is the only possible value of an expression of null type.

The null reference can always undergo a widening reference conversion to any reference type.

null参照が唯一の値です。null参照はワイドニング変換(widening conversion)で任意の参照型になります。

The direct supertypes of the null type are all reference types other than the null type itself.

http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.10.2

null typeの直接のスーパータイプはnull typeそれ自身を除く任意の参照型です。

使いどころ

これでコンパイルエラーにnull typeと出ても怖くなくないですね。