Add type parameter constraint to prevent abstract classes

前端 未结 3 1217
囚心锁ツ
囚心锁ツ 2021-02-20 03:27

Is it possible to restrict a type parameter to concrete implementations of an abstract class, if those implementations don\'t have default constructors?

For example, if

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 04:17

    You can add the new() constraint, which will require that the class not be abstract and have a default constructor.

提交回复
热议问题