This declares the readObjectData
method generic, with one type parameter, T
.
public <T> ...
Then the return type is T
.
... T readObjectData(...
Without the initial <T>
, which is the generic type declaration, the symbol T
will be undefined.
In the parameter list, Class<T> type
is one of the parameters. Because the return type and this parameter both reference T
, this ensures that if you pass in a Class<String>
, then it will return a String
. If you pass in a Class<Double>
, then it will return a Double
.
To pass in the parameter, pass in any Class
object, e.g. String.class
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…