I have the following code:
protected <T> T getValueForKey(String key) {
T value = null;
// currentStats is just a Bundle
if (currentStats.containsKey(key)) {
return value;
}
return value;
}
如何设置限制?例如,将T设置为String或int或double。这是否可行?
附注:我不想使用***。
protected <T extends String> T getValueForKey(String key) {
}
因为我不想仅仅只有字符串..
(因为我不想只使用字符串..)
<T extends String> == <String>
,因为String是final的。 - assyliasnull
值?你能让这个例子更加现实吗? - Peter Lawrey