Handle iteration manually, by defining your own implementation of Iterable.
手动处理遍历,定义自己的Iterable实现。
Trying to get an Iterator on a Map fails at compile time — Maps don't implement the Iterable interface.
在编译时,尝试对Map获取Iterator会导致失败 —Map 并没有实现Iterable接口。
Extend an existing collection class that already implements Iterable (and therefore already supports for/in).
扩展现有的、已经实现了 Iterable(因此也就已经支持for/in)的集合类。
Actually, this enhancement works with any object that implements the Iterable interface, not just Collections.
实际上,这个增强适用于实现Iterable接口的任何对象,而不仅仅是Collections。
The enhanced for loop (also sometimes known as "for-each" loop) can be used for collections that implement the Iterable interface and for arrays.
改进for循环(有时被称为“for - each”循环)能够用于实现了iterable接口的集合类及数组中。
As you can see, though, it takes a lot more to implement the Iterable interface manually than simply extending a class that does this work for you.
但是,您可以看到,与扩展一个现成的类来完成同样的工作相比,手动实现Iterable接口需要做的工作多得多。
For cases where the child collection is obvious and apparent, however, Iterable makes programming against the domain type much easier and more obvious.
但是,如果孩子集合比较明显,Iterable可以使针对域类型的编程更容易,更直观。
Anything that provides an Iterable facility (technically a trait in Scala, but think of it for now as an interface) can be used as the heart of the for expression.
提供Iterable功能(从技术上说,它是Scala中的一个特征,但现在将它视为一个接口)的任何东西都可以用作for表达式的核心。
Anything that provides an Iterable facility (technically a trait in Scala, but think of it for now as an interface) can be used as the heart of the for expression.
提供Iterable功能(从技术上说,它是Scala中的一个特征,但现在将它视为一个接口)的任何东西都可以用作for表达式的核心。
应用推荐