What does the `new` keyword do

后端 未结 9 1910
情深已故
情深已故 2020-12-01 09:41

I\'m following a Java tutorial online, trying to learn the language, and it\'s bouncing between two semantics for using arrays.

long results[] = new long[3]         


        
9条回答
  •  情书的邮戳
    2020-12-01 10:22

    The new keyword in Java creates a new object. In this case it is creating an array ... which is an object.

    Those two forms are equivalent. The second one is just a convenient shorthand for the first one. It is syntactic sugar.

    Are there certain "array" specific methods that won't work on an array unless it's an "array object"?

    All arrays are objects. Period.

    Is there anything that I can't do with an "array object" that I can do with a normal array?

    See above.

    Does the Java VM have to do clean up on objects initialized with the new operator that it wouldn't normally have to do?

    No. There is no difference between the objects created in different ways as far as the JVM is concerned.

提交回复
热议问题