Require override of method to call super

前端 未结 7 2351
既然无缘
既然无缘 2020-12-17 08:11

I want that when a child class overrides a method in a parent class, the super.method() is called in that child method.

Is there any way to check this a

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 08:41

    solution:

    Look at the findBugs project ...

    • FindBugs
      • Annotations package

    Example ...

        import javax.annotation.OverridingMethodsMustInvokeSuper;
           :
    
        @OverridingMethodsMustInvokeSuper
        protected String getLabel(){
           ... 
        }
    

    Override:

        @Override
        protected String getLabel(){
           // no call to Super Class!!
           // gives a message 
           ... 
        }
    

    I've been using it for about 3 years. No kittens have been harmed.

提交回复
热议问题