Constructor in an Interface?

前端 未结 11 1053
鱼传尺愫
鱼传尺愫 2020-12-02 06:38

I know it\'s not possible to define a constructor in an interface. But I\'m wondering why, because I think it could be very useful.

So you could be sure that some fi

11条回答
  •  萌比男神i
    2020-12-02 07:21

    Taking some of the things you have described:

    "So you could be sure that some fields in a class are defined for every implementation of this interface."

    "If a define a Interface for this class so that I can have more classes which implement the message interface, I can only define the send method and not the constructor"

    ...these requirements are exactly what abstract classes are for.

提交回复
热议问题