- <P>import java.util.*;
- class GenericDemoNew
- {
- public static void main(String[] args)
- {
- ArrayList<String> al = new ArrayList<String>();
- al.add("abc");
- al.add("abb");
- al.add("aba");
- printColl(al);
- }
- public static <String> void printColl(ArrayList<String> al)
- {
- Iterator<String> it = al.iterator();
- while (it.hasNext())
- {
- System.out.println(it.next().length());
- }
- }
- }</P>
- <P>printColl方法我已经明确了String类型那么为什么不能使用length()方法?</P>
复制代码 |