问题
For example, in the following code
public <U extends Number> void inspect(U u){
// Some method
}
what is the purpose of (what is this line doing or how is it read) that comes just before the return type
回答1:
This is the syntax that makes your method (as opposed to your class) generic.
Methods of regular and generic classes can be made generic on their own type parameters. In this case, your inspect
method is generic on U
, which must be a type extending from Number
.
来源:https://stackoverflow.com/questions/33468076/what-is-the-purpose-of-generics-before-return-type