import java.util.*;
public class LongWordFinder{
             public static void main(String []args){              String[] array={"123","12345","1","12","1234567"};
              List<String>list=Arrays.asList(array);
              Collection<String> resultList =getLongWords(list);
            }
            public static <E extends CharSequence>Collection<? extends CharSequence> getLongWords (Collection<E> coll)
{             
                Collection<E> longWords=new ArrayList<E>();
                for(E word: coll)
                    if(word.length()>6) longWords.add(word);
                return longWords;
}
}

解决方案 »

  1.   

    请你解释一下下面那个函数返回类型为什么必须是
    <E extends CharSequence>Collection<? extends CharSequence>
      

  2.   

    你的JDK必须是1.5版本或以上才有泛型的以前的版本当然编译通不过了
      

  3.   

    编译不通过也要把出错的地方报出来呀,不然怎么看List<String>list=Arrays.asList(array);这里的list前加空格
      

  4.   

    我没用过范性,觉得语法蛮奇诡的,为啥么有个?啊不过你的问题是强制转化一下类型就可以 Collection<String> resultList =(Collection<String>)getLongWords(list);
      

  5.   

    public static <E extends CharSequence>Collection<? extends CharSequence> getLongWords (Collection<E> coll)
    你的方法里 <? extends CharSequence>这句返回的是未定型的Collection<>
    而你在main()里 
    却把他赋给一个定型的Collection<String> resultList =getLongWords(list);
    所以报错了
    解决办法 
    第一种改方法
    public static <E extends CharSequence>Collection<E> getLongWords (Collection<E> coll)
    第二种
    改Collection<String> resultList =(Collection<String>)getLongWords(list);//强制转换