开发者

java generic parameterized type

开发者 https://www.devze.com 2023-03-05 11:39 出处:网络
Sorry for this simple question In this class class GenericTest{ static <T> List<T> getList(List<T> list){

Sorry for this simple question

In this class

class GenericTest{
    static <T> List<T> getList(List<T> list){
        return list;
    }
}

why this this <T> just after static needed in the declaration. I thought th开发者_开发百科e return type List<T> is fine.


You are declaring that this method has a type parameter "T". If you didn't declare it then there is no way for the compiler to know what type you're talking about (T is not declared anywhere else).

0

精彩评论

暂无评论...
验证码 换一张
取 消