java Generic Type Parameters (Type Parameters) Type Parameters Bound Type

Bound type

In addition to primitive and array, all can be used as boundary types

<T extends Number >
<T extends String >
<T extends Runnable > 
<T extends Thread.State >
<T extends List >
<T extends List<String> >

These two won't work

<T extends int >
<T extends Object[] >

You can use type parameters as boundaries

class Line <T> {
    
    
    private T fst, snd;
    public < X extends T , Y extends T> Line(X arg1, Y arg2) {
    
    
        fst = arg1;
        snd = arg2;
    }
}

Refer to
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#FAQ001

Guess you like

Origin blog.csdn.net/claroja/article/details/114108427