Re: [問題] generic type parameter bound?
: 推 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
討論串 (同標題文章)