[英]Comparator.reverseOrder() vs Collections.reverseOrder()
Is there a difference between the two?两者有区别吗? If so, what is it?
如果是这样,它是什么?
When I used them for a priority queue, the both sort it the same way.当我将它们用于优先级队列时,两者的排序方式相同。
If you use a good IDE, it's very easy to see the source code of the Java Runtime Library methods.如果您使用好的 IDE,很容易看到 Java Runtime Library 方法的源代码。 Eg in Eclipse you press F3 when cursor is on the method.
例如,在 Eclipse 中,当 cursor 使用该方法时,您按 F3。
If you do that on the Comparator.reverseOrder()
method, you'll see:如果你在
Comparator.reverseOrder()
方法上这样做,你会看到:
public static <T extends Comparable<? super T>> Comparator<T> reverseOrder() {
return Collections.reverseOrder();
}
Conclusion: They are exactly the same.结论:它们完全一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.