You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have found some usage of “int a = Integer.valueOf(String)” in this project.
In fact the return type of “Integer.valueOf()” is “Integer” which is wrapper class. Wrapper class stores in the heap rather than stack. It take more time to loopup. The other potential problem is that Java implement autoboxing and unboxing since JDK 1.5. If run this in low version JDK, it may get trouble.
Furthermore, in the above case, it need to cast Integer to int.
I recommend use “Integer.parseInt(String)” which return type is int to improve its performance.
PS:
This case also applies to “double-Doubel”, “float-Float”, “long-Long” and so on.
Hi,
I have found some usage of “int a = Integer.valueOf(String)” in this project.
In fact the return type of “Integer.valueOf()” is “Integer” which is wrapper class. Wrapper class stores in the heap rather than stack. It take more time to loopup. The other potential problem is that Java implement autoboxing and unboxing since JDK 1.5. If run this in low version JDK, it may get trouble.
Furthermore, in the above case, it need to cast Integer to int.
I recommend use “Integer.parseInt(String)” which return type is int to improve its performance.
PS:
This case also applies to “double-Doubel”, “float-Float”, “long-Long” and so on.
Detail websites and lines are listed below
109 110 154 155 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/admin/StoreBookController.java
85 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/admin/StoreController.java
33 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/service/impl/StoreServiceImpl.java
Best regards
你好,我在您的项目中发现了一些 int a = Integer.valueOf(String) 的使用形式
Integer.valueOf(String) 的返回类型是Integer, java 1.5之后虽然会自动将Integer强制转化为int,但会造成不必要的性能消耗,并且如果低版本的JDK上就会报错。
我推荐使用Integer.parseInt(String) 来代替,这个API的返回类型是int,能减少性能的消耗。
具体的网页和行数如下
109 110 154 155 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/admin/StoreBookController.java
85 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/admin/StoreController.java
33 | https://github.com/ZHENFENG13/ssm-demo/blob/master/ssm-demo/src/com/core/service/impl/StoreServiceImpl.java
The text was updated successfully, but these errors were encountered: