Java generics constraint require default constructor like C#

后端 未结 3 1044
一向
一向 2020-12-21 05:03

In C#, I can put a type constraint on a generic parameter that requires the generic type to have a default parameterless constructor. Can I do the same in Java?

In

3条回答
  •  轮回少年
    2020-12-21 05:55

    No.

    Because of type erasure, the type of is not known at runtime, so it's inherently impossible to instantiate it.

提交回复
热议问题