Collections.sort implementation

后端 未结 5 1898
灰色年华
灰色年华 2021-02-08 18:38

I can not understand the method implementation and the logic of Collections.sort method. Here is the method implementation i found,

public static 

        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 19:04

    First of all this method return type is void. What is > does in the method signature?

    is a generic Type that you use in your method, T could only be an object which implements java.util.Comparable.

    for example if you want to pass a List to the sort method it'd compile as java.lang.String implements java.lang.Comparable, but if you pass List you'd get a compiler error unless Animal implements java.lang.comparable

提交回复
热议问题