use*_*188 5 java generics methods
我看到了这个:
public static <T,U extends T> AutoBean<T> getAutoBean(U delegate)
Run Code Online (Sandbox Code Playgroud)
我知道输入类是U类型,而AutoBean类是T类型,而U扩展T是边界。但是,这<T,是什么意思呢?
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!
它只是声明您的方法处理的类型。也就是说,它基本上必须首先声明泛型类型名称,然后才在签名中使用它们。<T本身没有任何意义,但尖括号内的字母表示“这是我将在该方法中使用的类型”。
至于“myFunction()”处理以下输出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
}
Run Code Online (Sandbox Code Playgroud)