Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?

前端 未结 2 1237
暖寄归人
暖寄归人 2020-12-14 05:34

Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?

Is this a historical accident or intentional? The documentation clearly states

2条回答
  •  萌比男神i
    2020-12-14 05:56

    It is reasonable to expect the same exceptions to be thrown for null; however, these api's are very old and may not be able to be changed at this point.

    And:

    Since the exception behavior is long-standing and specified in the JavaDoc, it is impractical to change either method's behavior at this time. Closing as will not fix.

    As taken from: Bug Report: Integer.parseInt() and Double.parseDouble() throw different exceptions on null.

    Like others have stated: It's likely made by different authors.

提交回复
热议问题