Answer the question
In order to leave comments, you need to log in
Why is a constructor in a wrapper class deprecated with JDK9?
Hello, I'm reading Schildt's book on Java.
Question on wrapper classes, quote:
The Character( ) constructor has the following form: Character (char character)
But as of JDK9, the Character class constructor is no longer recommended. The current recommendation for obtaining a Character object is to use the static valueOf( ) method. This method returns an object of type Character that encloses the character value ch of the primitive type char
Answer the question
In order to leave comments, you need to log in
Modern architectural principles favor factory methods. Good manners dictate that a constructor does nothing but initialize fields. A factory method, on the other hand, can do a lot of additional operations, such as interning. A factory method can perform instance-level operations, such as returning a singleton. A factory method can return not only an instance of a class, but also its subtypes. Factory methods can have meaningful names. Etc. etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question