Bound mismatch for java Collections sorting

后端 未结 2 1648
春和景丽
春和景丽 2021-01-17 01:39

Hi need Help regarding java collection sorting. It gives me this error:

Bound mismatch: The generic method sort(List) of type Collections is not app         


        
2条回答
  •  灰色年华
    2021-01-17 02:13

    You can't sort a List of objects that don't implement the Comparable interface. Or rather, you can, but you have to provide a Comparator to the Collections.sort() method.

    Think about it: how would Collections.sort() sort your list without knowing when a WifiSSID is smaller or bigger than another one?

    You want to use Collections.sort(wifiList, new SortSSIDByid());

    EDIT:

    You defined your own proprietary Comparator interface, and implement this proprietary Comparator interface in SortSSIDByid. Collections.sort() wants an intance of java.util.Comparator. Not an instance of your proprietary Comparator interface, that it doesn't know.

提交回复
热议问题