Calling only the super method in the Override class

I see this piece of code in the Jenkins plugin and I think it is non-op

  @Override
  public DescriptorImpl getDescriptor() {
    return (DescriptorImpl)super.getDescriptor();
  }

Any reason this could be significant and cannot be inferred from code?

+4
source share
1 answer

During an override, you can change the return type (if the new return type is a subclass of the old return type).
For instance:

public class A {
  public Number getNumber() { /* ... */ } ;
}

public class B extends A {
  @Override
  public Integer getNumber() { /* ... */ } ;
}

In your example, super.getDescriptor()it can always return an object DescriptorImpl, so you can override this method to avoid being injected into your code.

+6
source

Source: https://habr.com/ru/post/1537920/


All Articles