0
还有就是generics here泛型类型类defition
一个很好的讨论,但是他们都谈阶级如何接受泛型类型变量。我的问题是在泛型类定义上。
的类定义为
protected final <T> T getBeanFromSpringContext(String name, Class<T> requiredType) {
if(springApplicationContext != null) {
return springApplicationContext.getBean(name, requiredType);
} else {
return null;
}
}
现在我明白了,返回类型为T
。但在此之前<T>
是由此Class对象建模的类的类型。为什么这不是<?>
,因为我不知道类型?
而且自返回类型是T
。如上所述,这个班级能否返回null
?
顺便说一句,我喜欢这种单线条样式:'回报springApplicationContext == NULL? null:springApplicationContext.getBean(name,requiredType);' – Bohemian 2012-01-06 10:37:53