(1)问号("?")是通配符吗,
(2)A选项的意思是:   判断语句List l = new List<A>();的正误   吗?
(3)D选项中,对于分配给List<? extends B>的List实例,该实例里的元素是应该满足IS-A B,还是应该满足IS-A B or IS-A ?("?"可能是继承于B的任意类)
(4)F选项中,ant List reference和List<?>还有List<Object>还有List四者有什么区别?希望能够举例
我觉得答案应该是ABE
Question 179
Given:
classA {}
class B extends A {}
class C extends A {}
class D extends B {}
Which three statements are true? (Choose three.)
A. The type List<A> is assignable to List.
B. The type List<B> is assignable to List<A>.
C. The type List<Object> is assignable to List<?>.
D. The type List<D> is assignable to List<? extends B>.
E. The type List<? extends A> is assignable to List<A>.
F. The type List<Object> is assignable to any List reference.
G. The type List<? extends B> is assignable to List<? extends A>.
Answer: CDG

解决方案 »

  1.   

    是通配符泛型。
    C. The type List<Object> is assignable to List<?>.
    D. The type List<D> is assignable to List<? extends B>.
    G. The type List<? extends B> is assignable to List<? extends A>.
    其中 List<? extends B> 表示任何泛型类型,它的类型参数是 B 的子类。
      

  2.   

    A是指像 List s = new ArrayList<A>(); 这样是否可以。
      

  3.   

    A:<>两边都要有,这是规定,没有为什么
    B:类型不匹配,所以错误
    C:正确,<Object>和<?>等价的
    D:正确,给出B的正确答案,<? extends B>表示B的任何子类型,D是B的子类,所以可以
    E:反过来就可以,参照D答案
    F:正确,任何B的子类,也都是A的子类,所以可以
      

  4.   

    (3)D选项中,对于分配给List <? extends B>的List实例,该实例里的元素是应该满足IS-A B,还是应该满足IS-A B or IS-A ?("?"可能是继承于B的任意类) 
    (4)F选项中,ant List reference和List <?>还有List <Object>还有List四者有什么区别?希望能够举例
      

  5.   

    <Object> 和 <?> 完全两码事。
      

  6.   

    针对选项B,让A是B C父类型
    List<B> listB = new ArrayList<B>();
    List<A> listA = listB; // actually fails here! let's assume it's allowed
    listA.add(new C()); // C is an A
    B first = listB.get(0); // class cast exception, as C is not compatible with B有一段解释
    there is a relationship based on the type arguments. The prerequisite is that at least one of the involved type arguments is a wildcard. For example, Collection<? extends Number> is a supertype of Collection<Long> , because the type Long is a member of the type family that the wildcard " ? extends Number " denotes.  更多请看
    http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ207
      

  7.   

     你说得对<Object> 和 <?> 完全两码事
    <Object>跟其他的<A>,<B> 一样,只可以接受List<Object>,只是空上List可以添加任何对象进来
    <?>可以接受任何类型,包括<A>,<B>,当然也包括<Object>,C选项还是正确的
      

  8.   

    应该说List<? extends Object>和List<?>才是完全等同的,都可以接受任何对象
      

  9.   

    放弃解释,楼主手边如果有 Core Java 第7版,请看看677页 13.8.2无限定通配符。泛型高级用法全掌握并描述清楚两个脑袋怕是都不够用。