Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Improvement of Java Autoboxing and Unboxing #21

Open
o0lwj0o opened this issue Jan 10, 2019 · 0 comments
Open

Suggestion: Improvement of Java Autoboxing and Unboxing #21

o0lwj0o opened this issue Jan 10, 2019 · 0 comments

Comments

@o0lwj0o
Copy link

o0lwj0o commented Jan 10, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant