开发者

java generic parameterized type

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜