java 自己定义了一个泛型类 怎么初始化啊? 我知道不能传入简单类型的 但是把main方法里的int改为Integer还是要报错 纠结啊。。

jingaita jingaita 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public class ArrayIterator<T> {
private T[] contents;
private int count;
private int i = 0;
public ArrayIterator(T[] contents,int count){
this.contents = contents;
this.count = count;
}

public boolean hasNext()
{
if(i<count)
return true;
else return false;
}

public T next()
{
return contents[i++];
}
}
class M
{
public static void main(String[] args)
{
int[] a = {1,2,3,4,5,6};
ArrayIterator<int> ai = new ArrayIterator<int>(a,a.length);
}
}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
jingaita
Java SE 62,620 成员 307,251 内容