integer - Why int primitive type not deprectaed in Java -


In Java, if integer should be used in place of int After providing additional features and integer my question is why why int is not being dropped, and why the int primitive type is so many Is used extensively?

Why is it not a simple reason that int is fast And although you can use both, but integer is a better option (as some introduction of an additional overhead of integer boxing and unboxing as ), because it Null . int will be zero

From the docs:

However, very different things are going on under the cover. An int is a number; A> Integer is an indicator that can refer to an object in a number.

...

is not an int object and requires an object, a common case is using the collection sections provided (list, map, set) - However it is possible to write versions of these sections which provide similar capabilities to the object versions. The cover sections (integer, double, etc.) are required whenever introspection is used (like in the reflection API).

Edit: - Joshua Bloch reason is too good:

  // Slowly slow program! Can you see the creation of the object? Public static zero main (string [] args) {long amount = 0 L; For (tall I = 0; i  

This program gets the correct answer, but due to this one-letter typographic error it is very slow. The variable amount is declared as a long rather than a long time, which means that about 2 ^ 31 unnecessary long examples (about a long period of time is added for long periods of time for each time) are formed. is.

P>

Comments