哪个更好:让Java进行自动装箱或使用valueOf() [英] Which is better: letting Java do autoboxing or using valueOf()

查看:109
本文介绍了哪个更好:让Java进行自动装箱或使用valueOf()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道让java autobox说一个整数有什么区别:

I am just wondering is there any difference in letting java autobox say an integer:

Integer myInteger = 3; // This will call Integer.valueOf()

或将代码设为

Integer myInteger = Integer.valueOf(3);

这有什么微观优化吗?我知道第二个更明确,但它也更不必要打字,除此之外还有什么不同吗?。

Is there any micro optimization on this? I know the second one is more explicit, but it is also more unnecessary typing, is there any difference besides this?.

推荐答案

无论如何它们在内部是相同的,所以使用第一个变体。机会很好,未来的编译器优化可能会使未来的第一个更快。

They are equal anyway internally, so use the first variant. Chances are good, that future compiler optimizations may make the first even faster in the future.

这篇关于哪个更好:让Java进行自动装箱或使用valueOf()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆