简体   繁体   English

Java集合类型不匹配:无法从TreeSet转换为SortedSet

[英]Java collection Type mismatch: cannot convert from TreeSet to SortedSet

package collection;

import java.util.*;

public class SortedSet {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

         SortedSet set = new TreeSet();

    }

}

It giving me following error: 它给了我以下错误:

Type mismatch: cannot convert from TreeSet to SortedSet

Your class name is also SortedSet , so it is hiding java.util.SortedSet . 您的类名也是SortedSet ,因此它隐藏了java.util.SortedSet Either rename your class (the preferred option) or use the full name of the interface in your variable declaration. 重命名您的类(首选选项)或在变量声明中使用接口的全名。

你有两个选择: - 更改类的名称, - 将set的类型更改为TreeSet,如TreeSer set = new TreeSet();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java - 类型不匹配:无法从元素类型 Object 转换为 String - Java - Type mismatch: cannot convert from element type Object to String Java类型不匹配:无法从java.lang.Object转换 - Java Type mismatch: cannot convert from java.lang.Object Java:类型不匹配:无法从 null 转换为 int - Java: Type mismatch: cannot convert from null to int Java-类型不匹配:无法从CommandSender转换为Player - Java - Type mismatch: cannot convert from CommandSender to Player Java-类型不匹配:无法从ImmutableList转换 <Object> 到ImmutableList <String> - Java - Type mismatch: cannot convert from ImmutableList<Object> to ImmutableList<String> 类型不匹配:无法从java.lang.String转换为String - Type mismatch: cannot convert from java.lang.String to String Java 8-类型不匹配:无法从列表转换 <Serializable> 列出 <String> - Java 8 - Type mismatch: cannot convert from List<Serializable> to List<String> Java GUI错误-类型不匹配:无法从字符串转换为双精度 - Java GUI error - Type mismatch: cannot convert from String to double Java泛型:类型不匹配:无法从Integer转换为K - Java generics : Type mismatch: cannot convert from Integer to K Java类型不匹配-无法从构造函数中的int [] []错误转换 - Java Type mismatch - cannot convert from int[][] error in constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM