![](/img/trans.png)
[英]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.