Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deprecated wrapper classes constructors

Why are constructors such as Integer(); Float(); Double(); Boolean(); deprecated? It’s recommended to use WrapperClassName.valueOf() but how does it differ? They return a new WrapperClass, I don’t seem to understand the point of it so can someone explain it to me?

Integer x = new Integer(4); // Deprecated since Java version 9, use Integer.valueOf(int)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Integer.valueOf caches small values.

If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading