返回类型之前泛型的用途是什么? [英] What is the purpose of generics before return type

查看:145
本文介绍了返回类型之前泛型的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在以下代码中:

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

推荐答案

常规类和泛型类的方法可以在它们自己的类型参数上通用。在这种情况下, inspect 方法在 U 上是泛型的,它必须是一个从号码

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.

这篇关于返回类型之前泛型的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆