Skip to content
Advertisement

Deprecated Short(String) how to update?

I’m handling this problem:

produto.setQuantidade(new Short("7"));

Short appears deprecated with a mark. How can I update this for above Java 9 versions? (Now, I have Java 11)

Advertisement

Answer

You shall use Short.valueOf. This is taken from the javadoc

Deprecated. It is rarely appropriate to use this constructor. The static factory valueOf(short) is generally a better choice, as it is likely to yield significantly better space and time performance

Note: The public constructor is up forRemoval starting Java-16.

Advertisement