从AbstractList中创建只读的List

zhangrongchao_ zhangrongchao_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package collection;

import java.util.AbstractList;

public class CountingIntegerList extends AbstractList<Integer>{
private int size;

public CountingIntegerList(int size){
this.size = size <0 ? 0 : size;
}
public Integer get(int index) {
return Integer.valueOf(index);
}

public int size() {
return size;
}

public static void main(String[] args) {
System.out.println(new CountingIntegerList(30));
}

}

输出:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

有谁能为我解释一下,为什么会有这样的输出。
...全文
评论 9
收藏 已收藏
分享
返回顶部
zhangrongchao_
Java 51,407 成员 86,128 内容