数组的the aggregate initialization和dynamic aggregate initialization

来源:互联网 发布:如何修改淘宝店铺名称 编辑:程序博客网 时间:2024/06/05 13:21

class Weeble {} // A small mythical creaturepublic class ArraySize {  private static Test monitor = new Test();  public static void main(String[] args) {    // Arrays of objects:    Weeble[] a; // Local uninitialized variable    Weeble[] b = new Weeble[5]; // Null references    Weeble[] c = new Weeble[4];    for(int i = 0; i < c.length; i++)      if(c[i] == null) // Can test for null reference        c[i] = new Weeble();    // Aggregate initialization:    Weeble[] d = {      new Weeble(), new Weeble(), new Weeble()    };    // Dynamic aggregate initialization:    a = new Weeble[] {      new Weeble(), new Weeble()    };  }}




     聚集初始化数组 ——》如:int[ ] dots = {6,4,8};      // 声明、构建、初始化 在一条语句中进行
    The aggregate initialization must be used at the point of definition

     动态聚集初始化数组(匿名数组) ——》 如:new int[ ]{6,4,8};     // 构建、初始化 在一条语句中进行
     The next array initialization can be thought of as a "dynamic aggregate initialization."
     W ith this syntax you can create and initialize an array object anywhere.