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

后端 未结 4 1012
借酒劲吻你
借酒劲吻你 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 17:54

    I think because Null can be cast in to any type of reference.so in compile time its nothing wrong if you are throwing null instead of throwable.

提交回复
热议问题