作者macbuntu (邀怪)
看板java
标题Re: [问题] generic type parameter bound?
时间Sat May 2 23:20:15 2009
: 推 TsaiCF:请比较 List<String[]> 跟 List<String>[]. 何者不合法? 05/02 01:19
: → macbuntu:你写的这两个都没有 type bounds... 05/02 01:23
: → macbuntu:type bound 是像 <T extends A,B> 中的 A 和 B, 不是 T 05/02 01:25
: 推 TsaiCF:List<? extends Object[]> z = new ArrayList<String[]>(); 05/02 13:37
疑,我没注意到这个过耶,这样看 Java parameter type bounds 的规则
怎麽变得有点不一致?
class A<T extends Object> { } // OK
class B<T extends
Object[]> { }
// compile-time error
void func() {
A<? extends
Object[]> a;
// OK
}
如果 Java 语法可以准许宣告变数 a 时使用 array type 当作 type bound,
为什麽要在定义型别 B 时不准使用 array type?
这是有什麽特别的考量吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.132.21