Java, the generic <T> T and T usage

<T> T represents the return value is a generic, what is transmitted, it returns what type of data, and T is represented by a separate parameter type you pass limit, in this case, returned through a generic way, obtain each a first set of data, <T> T and T is the value returned by two methods.

A, <T> T achieved:

    / ** 
     * <T> T can pass any type of List 
     * parameter T 
     * is represented by a first generic 
     * represents a second return type of data is T 
     * third limit parameter of type T 
     * @param Data 
     * @return 
     * / 
    Private <T> T getListFisrt (List <T> Data) {
         IF (Data == null || data.size () == 0 ) {
             return  null ; 
        } 
        return data.get (0 ); 
    }

two,

    / ** 
     * This type of data can only pass T 
     * return value is the type of object is instantiated passed 
     * @param Data 
     * @return 
     * / 
    Private T getListFisrt (List <T> Data) {
         IF (Data == null || data.size () == 0 ) {
             return  null ; 
        } 
        return data.get (0 ); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/lcx20190724xxz/p/11237109.html