< T,U的含义是扩展T>的含义.在Java函数声明中 [英] Meaning of <T, U extends T> in java function declaration
问题描述
我看到了:
public static <T,U extends T> AutoBean<T> getAutoBean(U delegate)
我知道输入类是U类型,而AutoBean类是T类型,而U扩展T是边界.但是<T,
在这里是什么意思?
此外,如果我要编写一个函数来接受getAutoBean的输出,您将如何编写函数声明? (即myFunction(getAutoBean(...)),myFunction()的函数声明是什么?)
谢谢!
它只是声明您的方法要处理的类型.也就是说,它基本上必须首先声明泛型类型名称,然后才在签名中使用它们. <T
本身并不意味着任何东西,但是尖括号中的字母表示这里是我要在方法中使用的类型".
关于"myFunction()"以与getAutoBean(...)
的输出一起使用:
I am seeing this:
public static <T,U extends T> AutoBean<T> getAutoBean(U delegate)
I know the input class is of U type and AutoBean class is of T type and U extends T is the boundary. But what does <T,
mean here?
Also, if I am going to write a function to accept the output of getAutoBean, how would you write the function declaration? (i.e. myFunction(getAutoBean(...)), what will the function declaration of myFunction() be?)
Thank you!
It just declares the types that your method deals with. That is to say, that it basically has to first declare the generic type names, and only then use them in the signature. <T
doesn't mean anything by itself, but the letters within angular brackets mean "Here are the types I am going to use in the method".
As to "myFunction()" to work with the output of getAutoBean(...)
:
public static <T> String myFunction(AutoBean<T> arg){ // If you return a generic type object, you will also have to declare it's type parameter in the first angular brackets and in angular brackets after it. // do work here }
这篇关于< T,U的含义是扩展T>的含义.在Java函数声明中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!