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