try to change the sort (), method of LinkedList, which originally implements interface list, but always reports an error. Please point out:
import java.util.*;
public class TestSort {
LinkedList mtn = new LinkedList();//
public static void main(String[] args){
new TestSort().go();
}
public void go(){
//
mtn.add("L1");
mtn.add("E2");
mtn.add("M3");
mtn.add("C4");
Compare_str nc = new Compare_str();//
/*:*/
mtn.sort(nc);
}
}
/ definition of comparator /
class Compare_str implements Comparator < String > {
public int compare(String one ,String two) {
return one.compareTo(two);
}
}
/ is here to test whether sort: can be overwritten in the basic class LinkedList /
class LinkedList implements List < String > {
public void sort(Compare_str testcomp){
System.out.println("test system method!");
}
/*
*TestSort.java:30: : LinkedList, ListsubList(int,int)
*class LinkedList implements List<String>{
*^
*1
*/
public LinkedList subList(int from ,int to){};//
/*
*TestSort.java:30: : LinkedList, ListlistIterator(int)
*class LinkedList implements List<String>{
*^
*1
*/
public Iterator<String> listIterator(int m){};//
/*
*TestSort.java:30: : LinkedList, ListlistIterator(int)
*class LinkedList implements List<String>{
*^
*TestSort.java:47: : LinkedListlistIterator(int)ListlistIterator(int)
* public Iterator<String> listIterator(int m){};//
* ^
*Iterator<String>ListIterator<String>
*, E:
*E ListObject
*2
*/
}