There is a nice discussion of generics here
But they all talk about how the class can accept generic type variable. My question is rather on the generic type class definition.
The class is defined as
protected final <T> T getBeanFromSpringContext(String name, Class<T> requiredType) {
if(springApplicationContext != null) {
return springApplicationContext.getBean(name, requiredType);
} else {
return null;
}
}
Now I understand that the return type is T
. But then <T>
before that is the type of the class modeled by this Class object. Why is this not <?>
as I don't know the type?
And since the return type is T
. Can this class return null
as is mentioned above?