我想注释 Vaadin 的 HasComponents 类,它扩展了 Iterable。我可以像这样注释迭代器()方法:
class com/vaadin/ui/HasComponents
iterator
()Ljava/util/Iterator<Lcom/vaadin/ui/Component;>;
()L1java/util/Iterator<L1com/vaadin/ui/Component;>;
这样我就可以使用经典的 for 循环进行迭代
for (Iterator<Component> it = content.iterator(); it.hasNext();) {
Component c = it.next();
doSmoething(c);
}
但是当我尝试像这样的foreach循环时
for(Component c : content) {
doSomething(c);
}
我收到来自 Eclipse 的警告:
Null type safety (type annotations): The expression of type 'Component' needs unchecked conversion to conform to '@NonNull Component'
大概是因为它应该是
HasComponents extends Component, Iterable<@NonNull Component>
有什么方法可以通过外部注释添加此注释,还是有其他方法?