constructor methods in interfaces

后端 未结 6 2194
闹比i
闹比i 2021-02-18 21:03

Are constructor methods in interfaces bad?

6条回答
  •  Happy的楠姐
    2021-02-18 21:16

    They are bad in that they serve no purpose. At its core, an interface is simply a data passing contract. There is no implemenation attached with an interface and hence there is nothing to initialize and no need for a constructor.

    If you need some sort of initialization your much better off using an abstract class.

提交回复
热议问题