不是要用return a.compareTo(b);进行比较的吗?compareTo()方法是在String类下面的
Compares two strings lexicographically. The comparison is based on the Unicode
value of each character in the strings. The character sequence represented by
this String object is compared lexicographically to the character
sequence represented by the argument string. The result is a negative integer if
this String object lexicographically precedes the argument string.
The result is a positive integer if this String object
lexicographically follows the argument string. The result is zero if the strings
are equal; compareTo returns 0 exactly when the equals(Object) method would return true.
sort会自动调用哪个compare方法,如果他没有实现,则无法排序,也就是顺序是混乱的。
另一方面,你指定了comp方法,则系统在每次需要比较时,都把2个对象传到里面,注意compareabel的参数是 (Object o1,Object o2)
也就是默认是Object类型的,里面怎么比较和类型判断是程序员的事情
当然你也可以启用泛型,指定compare的对象类型。
自定义排序方法