【问题标题】:Terminology of class components类组件的术语
【发布时间】:2012-04-14 05:51:39
【问题描述】:

您能告诉我以下代码中 Java 术语中ArrayList<Image>(第 4th 行)的名称是什么吗?

public class ImageCollection {
  private  int imageNum;                           // field
  private  String name;                            // field
  ArrayList<Image> album = new ArrayList<Image>(); // ???

  public ImageCollection(String n, int numIm) {    // constructor
    name = n;
    imageNum = numIm;
  }

  public set(String n) {                           // method
    name = n;
  }

【问题讨论】:

  • “名字”你想说什么?
  • 在listing中我写了构造函数、方法、两个字段,但是第四行怎么调用呢?
  • ArrayList&lt;Image&gt; album 是您的 ImageCollection 类的另一个字段,您只是没有提供可见性,因此它对于同一包中的所有类都是公共的,但对于包外的类是私有的。

标签: java terminology


【解决方案1】:
name - field of type String
album - field of type ArrayList<Image>, you can read it as list of images

【讨论】:

  • ArrayListImage 类模板
【解决方案2】:

这是一个字段声明。但是,它不是使用默认值 (null) 进行初始化,而是初始化为可能包含 Image 对象的空 ArrayList。

【讨论】:

    【解决方案3】:

    ArrayList 是一个“集合”字段,更具体地说是一个列表

    在代码块中,它被称为字段

    【讨论】:

      【解决方案4】:

      album 变量是图像列表 - ArrayList 是 List 对象的实现之一

      Arraylist javadoc

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-19
        • 2018-03-21
        • 1970-01-01
        • 1970-01-01
        • 2012-07-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多