【发布时间】:2019-11-24 14:20:40
【问题描述】:
我在编译代码的过程中遇到了“类型不匹配”的问题。其实我不知道为什么 List 不能转换为 ArrayList。我使用了 java.util.Collections.singletonList 并想转换为 List。
我尝试将表达式转换为 ArrayList,但无法转换。
public class AlphabeticShifts {
public static ArrayList<String> DoAlphapeticShifts(ArrayList<String> sentences) {
Collections.sort(sentences, String.CASE_INSENSITIVE_ORDER);
return sentences;
}
public static void main(String[] args){
DoAlphapeticShifts(java.util.Collections.singletonList("Array"));
}
}
例外:
java.lang.Error: Unresolved compilation problems:
The method DoAlphapeticShifts(ArrayList<String>) in the type AlphabeticShifts is not applicable for the arguments (List<String>)
Type mismatch: cannot convert from List<String> to ArrayList<String>
at AlphabeticShifts.main(AlphabeticShifts.java:15)
【问题讨论】:
标签: java list arraylist collections