Why is “throw null” not creating a compilation error in Java?

后端 未结 4 1007
借酒劲吻你
借酒劲吻你 2020-12-05 17:25
class ThrowNull {
    public static void main(String[] args) {
        throw null;
    }
}

We know that rule for throw is throw ThrowableInst

4条回答
  •  自闭症患者
    2020-12-05 18:14

    In generel, and not just throw. Any object variable can be assigned null. So we can see that throw is not a special case. Should it be? maybe. Is it consistent? Yes.

提交回复
热议问题