What does <T> T mean when used as a method signature? Is it a return type?

对着背影说爱祢 提交于 2019-12-01 08:08:54
mkobit

It is a generic method. The first is for the generic type that would be used. The function is also declaring that is returns that type T. The parameters are showing that they use that generic parameter type.

T is a generic type. It allows generic type invocation when using the class in actual code.

You may have also seen <K, V> in hash maps. Below is the legend for other parameters

E - Element (used extensively by the Java Collections Framework)
K - Key
N - Number
T - Type
V - Value
S,U,V etc. - 2nd, 3rd, 4th types

http://docs.oracle.com/javase/tutorial/java/generics/types.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!