no compile error as JLS: 14.18 The throw Statement
"The Expression in a throw statement must denote a variable or value of a reference type which is assignable (ยง5.2) to the type Throwable, or a compile-time error occurs."
JLS 5.2 Assignment Conversion
>A value of the null type (the null reference is the only such value) may be assigned to any reference type, resulting in a null >reference of that type.
So NPE:
>If evaluation of the Expression completes normally, producing a null value, then an instance V' of class NullPointerException is >created and thrown instead of null.
Although null is assignable to every reference type, the type of null is not itself a reference type. It was our intent that the requirement that the expression be a reference type was to be removed from the third edition of the JLS, but that change never actually made it into the published version. Thus, this is a javac compiler bug which I introduced in SE 5.
Comments
chist replied ago:
no compile error as JLS: 14.18 The throw Statement
"The Expression in a throw statement must denote a variable or value of a reference type which is assignable (ยง5.2) to the type Throwable, or a compile-time error occurs."
JLS 5.2 Assignment Conversion
>A value of the null type (the null reference is the only such value) may be assigned to any reference type, resulting in a null >reference of that type.
So NPE:
>If evaluation of the Expression completes normally, producing a null value, then an instance V' of class NullPointerException is >created and thrown instead of null.
Neal M Gafter replied ago:
Although null is assignable to every reference type, the type of null is not itself a reference type. It was our intent that the requirement that the expression be a reference type was to be removed from the third edition of the JLS, but that change never actually made it into the published version. Thus, this is a javac compiler bug which I introduced in SE 5.
Voters For This Link (19)
Voters Against This Link (5)