
[英]In Java is there a way to name an ArrayList inside the ArrayList?
[英]Java - name of ArrayList?
我有以下问题:
为什么在添加语句(add (pipedInstanceIterator.next()))
之前不必使用列表的名称?
谢谢。
public class InstanceList extends ArrayList<Instance> implements Serializable, Iterable<Instance>, AlphabetCarrying
...
public void addThruPipe (Iterator<Instance> ii)
{
//for debug
Iterator<Instance> pipedInstanceIterator = pipe.newIteratorFrom(ii);
while (pipedInstanceIterator.hasNext())
{
add (pipedInstanceIterator.next());
//System.out.println("Add instance " + pipedInstanceIterator.next().getName());
}
}
您的InstanceList
是ArrayList
的子类,因此它可以执行该类的任何公共或受保护的方法,而无需指定应为其执行它们的实例。
因为InstanceList扩展了ArrayList,所以任何未指定的方法都将在其上运行。 所以你添加到实例列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.