弃用的 Short(String) 如何更新?

Deprecated Short(String) how to update?

我正在处理这个问题:

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

Short 似乎已弃用并带有标记。我如何为以上 Java 9 个版本更新这个? (现在,我有 Java 11 个)

你应该使用Short.valueOf。这取自 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

注意:public 构造函数启动 forRemoval 开始 Java-16.