有如下一个类:
public class BaseDao<T> {
public <E> Page<E> find(Page<E> page, String qlString) {
return find(page, qlString, null);
}
public T get(String id){
return (T)getById(id);
}
}
对于get方法中的T,我能够理解,即外部传入的参数化类型
但是对于find方法中的E,表示不太理解,如果是简单的规范参数,为什么在返回类型的前面还要加一个<E>
求解惑
The first one is a generic method (the parameter list uses one or more generic types). The generic types used in the () method parameter list are listed in front of the method.
https://docs.oracle.com/javase/tutorial/extra/generics/methods.html
http://www.cnblogs.com/iyangyuan/archive/2013/04/09/3011274.html
Because this E type is not the generic type T given in the class definition
The generic parameters of the java method are written in front of the return value. c# is written after the method name.
Um, I don’t know if I understood it wrong. .
The T in get is not a canonical parameter but declares that the return type is T, right?
The page function only specifies that the parameter has page, and the page itself is of type E
This is a generic method, which means it receives Page whose type parameter is E and returns Page
The parameters and return value of the find method are of the type Page, but this Page is also generic. It can be run without writing, but there will be a warning