Why don't Java Generics support primitive types?

后端 未结 6 831
轮回少年
轮回少年 2020-11-21 07:18

Why do generics in Java work with classes but not with primitive types?

For example, this works fine:

List foo = new ArrayList

        
6条回答
  •  梦如初夏
    2020-11-21 07:51

    The collections are defined to require a type which derives from java.lang.Object. The basetypes simply don't do that.

提交回复
热议问题