[英]Iterator on generics with 'extends'
public class abc<X extends Z> implements Iterable<X>
{
protected ArrayList<X> list;
public Iterator<X> iterator()
{
return list.iterator();
}
}
I get a 'cannot find symbol' error for the iterator method. 我得到了迭代器方法的'找不到符号'错误。 I have honestly no clue why. 我老老实实不知道为什么。
You should give the exact error message, but my guess is that you need to import the Iterator
class ( java.util.Iterator
). 您应该给出确切的错误消息,但我的猜测是您需要导入Iterator
类( java.util.Iterator
)。
Also the way you have declared X
requires that you have some other class named Z
( X
is restricted to Z
or subclasses of Z
). 同时声明该方法X
需要你有一些其他的命名类Z
( X
限制为Z
或子类Z
)。 Is this true? 这是真的? If it is, you should rename it as only type parameters should have single-character names. 如果是,则应将其重命名为只有类型参数应具有单字符名称。 If it's not true, and you are considering Z
another type parameter, you would need to declare Z
as a type parameter somewhere. 如果不是这样,并且您正在考虑Z
另一个类型参数,则需要在某处将Z
声明为类型参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.