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

abstract public <T> T iterEdges(EdgeFun<T> func, T accum);


This is for a multi-threaded library for graphs. I am not asking for anything that is appropriate for a real implementation, I just don’t understand what the double return types mean?

I'm just guessing here, but this is my interpretation (I tried googling, but google doesn't match non-alphanumeric characters, so I tried a few combinations of terms but got nothing).

Does that just say it will return some T-type collection? The two classes extend the class that this method is inside of, and so I assume it allows polymorphism, but what is the true meaning of that?


source to share

2 answers

This is a common method . The first is for the generic type to be used. The function also declares that it returns type T. The parameters indicate that they use this generic parameter type.



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

You may have seen it <K, V>

in hash maps as well. Below is the legend for other parameters

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




All Articles