Elad Benda
Elad Benda

Reputation: 36656

why is @SuppressLint("WrongCall") required only after method extraction

I have this andorid code:

      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
       //some code
          super.onMeasure(widthMeasureSpec,heightMeasureSpec);
   ..
      }

no errors.

but when I extract the last lines into a private method I get this warning which requires to add a suppression annotation to the private method.

specious method call, should probably call measure

      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
       ...
        foo(textMaxWidth);
      }

      private void foo(int textMaxWidth) {
...
          super.onMeasure(widthMeasureSpec,heightMeasureSpec);
   ..
      }

why is the suppression needed only after extraction?

@SuppressLint("WrongCall")

Upvotes: 0

Views: 185

Answers (1)

TheWanderer
TheWanderer

Reputation: 17824

Because usually you only call super methods from their overrides, not from separate methods. And if you do call them from separate methods, you might not be overriding them (so super.whatever() is the same as whatever());

Your IDE is warning you of this in case you accidentally copied some code over and included that call by accident.

In your example code at least, I don't really see a reason to do the super call in a separate method though. If you need to contents of foo() to be called before the super method, just put it after you invoke foo().

Upvotes: 0

Related Questions