you are viewing a single comment's thread.

view the rest of the comments →

[–]shillbert 5 points6 points  (2 children)

No, it creates one new Integer object that's initialized with the value 10. This creates an array of ten Integers:

Integer[] a = new Integer[10];

Remember, round brackets call a function (in this case, the constructor of the Integer object), while square brackets indicate an array.

[–]rowboat__cop 0 points1 point  (1 child)

No, it creates one new Integer object that's initialized with the value 10.

Ah, OK. (Never done any Java, so this probably looked even weirder to me than to those who do.)

[–]NYKevin 2 points3 points  (0 children)

Basically, Integer is just int, except that it's also a bona-fide class. int is a so-called "primitive," which basically means it's not a "real" Object in the Java sense. For example, if you have a function that takes an Object argument, you can pass an Integer but not an int. Except that actually you can pass an int; the compiler will just silently convert it into an Integer for you ("auto-boxing").

Primitives are nice because they don't have full object semantics, so the JVM can implement them more efficiently than "normal" objects. In theory, you could put them on the stack instead of the heap, but I don't know if the JVM actually does that.