ZHENFENG13 / ssm-demo

:banana:Spring+SpringMVC+Mybatis+easyUI实现简单的后台管理系统
http://ssm-cluster.13blog.site
Apache License 2.0
1.83k stars 785 forks source link

Suggestion: Improvement of Java Autoboxing and Unboxing #21

Open o0lwj0o opened 5 years ago

o0lwj0o commented 5 years ago

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