I have this Java code.
public T readObjectData(ByteBuffer buffer, Class type) {
...
T retVal = (T) summaries;
return retVal;
The
part is declaring a generic type argument T
. If you were to omit this part, the compiler would likely complain that the type T
doesn't exist.
In this case, T
serves as a placeholder for an actual type, which will only be determined when the method is actually called with non-generic type arguments.
public T readObjectData(...
^ ^
| + Return type
+ Generic type argument