对于这个问题,我们假设可以在java中扩展类String。在下面的代码:Java - 通用类型
T getId () ;
void setId (T t) ;
}
public class Person implements Identifiable <String> { . . . }
public class Car implements Identifiable <Integer> { . . . }
public class UTFString extends String { . . . }
public class Tourist implements Identifiable <UTFString> { . . . }
Identifiable <Y> z ;
if (. . .) {
z = new Person () ;
} else {
z = new Tourist () ;
}
z.setId(new UTFString(…))
有人问我什么是正确的类型Y的我知道的Y
类型,应该是:? super UTF-STRING
,意思是:Identifiable <? super UTF-STRING> z
;但为什么?正如我所看到的,Persron和Tourist实现了接口UTFSTRING,为此它应该是? extends UTF-STRING
。我想念什么?
请问您是否可以更改您的问题,我无法理解一个单词! – doNotCheckMyBlog 2011-06-15 09:37:08
@krio:我编辑问题。 – Tom 2011-06-15 09:39:59
为什么你不提供一个我们不必假设不可能的例子?会使复制和播放更容易。 (这个问题使我无法花时间处理这个问题。) – musiKk 2011-06-15 09:44:26