What is the purpose of generics before return type

前端 未结 1 1955
暖寄归人
暖寄归人 2020-12-19 23:17

For example, in the following code

public  void inspect(U u){
// Some method
}

what is the purpose of (what is this

1条回答
  •  臣服心动
    2020-12-20 00:06

    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.

    0 讨论(0)
提交回复
热议问题