Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的项目中有以下代码行:
Iterator<Node> i = graph.nodes();
graph.nodes() 是 prefuse 中定义的方法。
现在我想向迭代器添加类型检查,但我该怎么做呢?
如果你使用Guava,你可以做
Iterator<Node> iterator = Iterators.filter(theOriginalIterator, Node.class);
返回的迭代器保证只继续与提供的类型相对应的元素。(顺便说一句,类似的方法也可用Iterable)
Iterable
看
Iterators.filter(iterator, class)
Iterables.filter(iterable, class)