I came across code written by a colleague:
return new Integer(_hash).compareTo(other.getHash());
and I am wondering if Java can optimize this avoid the boxing and simply compare the two integers. Does it do that (in Java 7 or 8), or does it continue creating an Integer and calling compareTo() each time?
In Java 7 and 8, surely you should just use Integer.compare
. Then you can totally avoid any boxing whatsoever. Simple!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.