标签:
Java Provides a number of ways to hold objects:
It‘s helpful to look at a simplified diagram of the Java containers(without the abstract classes or legacy components). This only includes the interfaces and classes that you will encounter on a regular basis.
图中,用粗黑线框包围的容器(HashMap、ArrayList、LinkedList、HashSet)是我们在开发过程中要频繁使用的;虚线框表示接口,实线框表示具体的实现类;空心箭头表示某一个类实现了所指向的接口,实心箭头表示一个类(或实现某个接口的类)能生成一个指向类的对象。
public class ArrayIsNotIterable { static <T> void test(Iterable<T> ib) { for(T t : ib) { System.out.print(t + " "); } } public static void main(String[] args) { test(Arrays.asList(1, 2, 3)); String[] strings = {"A", "B", "C"}; // An array works in foreach, but it‘s not Iterable: // !test(strings); // You must explicitly convert it to Iterable: test(Arrays.asList(strings)); } } /* Output: 1 2 3 A B C */
TIJ英文原版书籍阅读之旅——Chapter Eleven:Holding Your Objects
标签:
原文地址:http://www.cnblogs.com/xpjiang/p/5695891.html