RuntimeException()
Constructs a new runtime exception with null as its detail message.
RuntimeException(String message)
Constructs a new runtime exception with the specified detail message.
RuntimeException(String message, Throwable cause)
Constructs a new runtime exception with the specified detail message and cause.
Exception()
Constructs a new exception with null as its detail message.
Exception(String message)
Constructs a new exception with the specified detail message.
Exception(String message, Throwable cause)
Constructs a new exception with the specified detail message and cause.
Stephan van Hulst wrote:And what syntax would you propose for that?
Stephan van Hulst wrote:
Remember, according to your proposal, Integer should inherit the parameterless constructor from the Number class.
Stephan van Hulst wrote:
First of all, you're not supposed to instantiate an Integer directly. You're supposed to use a literal or one of the valueOf() factory methods. Secondly, if you DID instantiate an Integer directly, then what would it even mean to instantiate one without a value?
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
Tim Holloway wrote:Incidentally, Integer.valueOf(null) should, I think invoke the valueOf(String) version as only unambiguous match. And it it does, it won't throw a NullPointerException, it will throw a NumberFormatException.
java.lang.NumberFormatException: Cannot parse null string
at java.base/java.lang.Integer.parseInt(Integer.java:623)
at java.base/java.lang.Integer.valueOf(Integer.java:988)
at java.base/java.lang.Integer.valueOf(Integer.java:988)
Stephan van Hulst wrote:That would be a really bad idea.
In essence, that means that I can no longer control whether and how a caller makes an instance of my class, and it also means that I can create instances of classes without providing the bare minimum of information they need for initialization.
Consider the following example:
First of all, you're not supposed to instantiate an Integer directly. You're supposed to use a literal or one of the valueOf() factory methods. Secondly, if you DID instantiate an Integer directly, then what would it even mean to instantiate one without a value?
Remember, according to your proposal, Integer should inherit the parameterless constructor from the Number class.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |