What is the purpose of generics before return type

可紊 提交于 2019-11-28 05:14:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!