Jump over parent constructor to call grandparent's

后端 未结 10 1837
遥遥无期
遥遥无期 2020-12-18 22:27

The problem is this: I have an abstract class that does some work in its constructor, and a set of child classes that implement the abstract class:

class Abs         


        
10条回答
  •  别那么骄傲
    2020-12-18 22:55

    This sounds to me like a mixture of concerns - something Java is not well equipped to handle.

    While it is not the answer you were hoping for or one that I am proud to type, you could simply create ConcreteClass2 that mimics ConcreteClass1 and uses the AbstractClass's constructor.

    As @TofuBeer said, this is not something that Java supports. This is why some modern languages (i.e. Scala w/ Traits) are gaining passionate developers.

提交回复
热议问题