Generics cast issue

后端 未结 6 1161
悲哀的现实
悲哀的现实 2021-01-01 17:00

Here\'s my issue: given these classes

class A {}
class B extends A {}

This code compiles:

    List

        
6条回答
  •  春和景丽
    2021-01-01 17:41

    Arrays.asList(B.class);
    

    is generified as

    List> numbers = Arrays.asList(B.class);
    

    Since it has only 1 attribute of type T that match the parameterized type (in this case, B.class).

提交回复
热议问题