Is it faster (or better) to declare an array inline in Java?

前端 未结 7 1226
慢半拍i
慢半拍i 2021-01-11 17:20

Consider the following two method calls that are nearly equivalent. Take note of the way the byte array is declared and allocated on both.

void Method1()
{
          


        
7条回答
  •  春和景丽
    2021-01-11 17:54

    They are the same.

    new keyword creates an object. But in Java, arrays are.. objects. See Chapter 10. Arrays:

    In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array.
    ..
    An array is created by an array creation expression (§15.10) or an array initializer (§10.6).

提交回复
热议问题