Collections sort not being accepted by Eclipse

后端 未结 5 1594
梦如初夏
梦如初夏 2021-01-19 06:58
    import java.io.BufferedReader;
    import java.util.Collections;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader         


        
5条回答
  •  滥情空心
    2021-01-19 07:07

    The collection myCelebrityList is of type CelebrityNamesFile and that means it can only accept instances of that class. You need to create an instance of CelebrityNamesFile and add it to the collection. The Collections wont accept your collection because you class CelebrityNamesFile does not implement the Comparator interface. You need to pass your comparator instance to the Collections.sort() as second parameter.

提交回复
热议问题