Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer.valueOf() better than new Integer() [duplicate]

Tags:

java

Possible Duplicate:
New Integer vs valueOf

I read at few place that Integer.valueOf is better than new Integer(), since it allows caching of values to be done by the compiler. So when should I be using new Integer() and not Integer.valueOf(). Is there a reason/scenario where I should not be using Interger.valueOf()

Thanks

like image 513
javanerd Avatar asked Jan 20 '23 07:01

javanerd


1 Answers

No, there is no scenario where new Integer() should be used. If you are distinguishing integers by their wrapper object identity then you are not likely to be doing something reasonable.

like image 200
Mathias Schwarz Avatar answered Jan 28 '23 20:01

Mathias Schwarz