-
Notifications
You must be signed in to change notification settings - Fork 89
SpireOverride
Kiooeht edited this page Mar 23, 2023
·
3 revisions
For overriding private methods from a superclass.
Normally it is impossible to override a private method of a superclass:
class A
{
public void foo() {}
protected void bar() {}
private int baz(int i) { return i; }
}
class B extends A
{
// Good
@Override
public void foo() {}
// Good
@Override
protected void bar() {}
// Error
@Override
private int baz(int i) { return i + 1; }
}
But SpireOverride
allows you to:
class A
{
private int baz(int i) { return i; }
}
class B extends A
{
// Good
@SpireOverride
protected int baz(int i) { return i + 1; }
}
Note: Your SpireOverride method must be either protected
or public
. If you make it private
the SpireOverride will not work.
If you want to call the super version of the SpireOverride
method, use SpireSuper.call
:
@SpireOverride
protected int baz(int i)
{
// Error
return super.baz(i + 1);
// Use SpireSuper instead
return SpireSuper.call(i + 1);
}