Default comparator is not exist in Java. However, if you are coding with, for example, a customized searcher, which intends to use comparator rather than the compareTo() method of derived type of Comparable class, you may write a static inner comparator class as the default comparator, simply implementing the compare() method by calling the compareTo().
Example:
class Searcher> {
private Comparator comparator;
Searcher(Comparator<T> comparator) {
this.comparator = comparator;
}
Searcher() {
this(new DefaultComparator<T>());
}
int search(...) {
...
}
private static class DefaultComparator<E extends Comparable<E>>
implements Comparator<E> {
public int compare(E o1, E o2) {
return o1.compareTo(o2);
}
}