Should @ForOverride foo() permit super.foo() calls?
See original GitHub issueGuava has this situation:
class AbstractFuture {
// @ForOverride?
void done() {}
}
// There are multiple classes like the following:
class AggregateFuture extends AbstractFuture {
@Override final void done() {
super.done();
runningState = null;
}
}
We would like to apply @ForOverride
to done()
. But we can’t because of the super.done()
call[]. We don’t really *need that call, but it makes me feel safer to have it there. (I would also want it if we had multiple levels of done()
overrides down the hierarchy… though I suppose we could have done()
call a reallyDone()
method.) Another option is for us to make done()
abstract
so that we “know” we don’t need the super.done()
call. But we still don’t really “know” that unless we look at the superclass. Plus, it requires every subclass to override done()
, even though most don’t need to.
Possibilities for changes that might help us:
- Allow
super.done()
- Allow
super.done()
if the calling method is itself annotated@ForOverride
(but this would be weird in our case, wheredone()
is sometimesfinal
)
[*] Error:
error: [ForOverride] Method annotated @ForOverride must not be invoked directly (except by the declaring class, com.google.common.util.concurrent.AbstractFuture<V>)
super.done();
^
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Warn developer to call `super.foo()` in java - Stack Overflow
A method can be declared final to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override...
Read more >Replace the override keyword by 'extend' and 'replace' or add ...
Hi Recardo,. this will only work for calls inside the superclass, but for calls from outside the class you have no control. If...
Read more >Add a concise way to specify that an override method should ...
override fun foo(a:Int) by super(a+1) { } ... i.e. “super()” by itself is an expression that evaluates to a call to the parent...
Read more >Source code - Guava
149 protected Converter() { 150 this(true); 151 } 152 153 /** Constructor used ... the apply() method 485 * on a a Function<Foo,...
Read more >Diagnostic messages - Dart
When code refers to a member of an object (for example, o.m() or o.m or ... A constant constructor can't call a non-constant...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about only allowing super.done() inside an override of done?
Thanks @lukesandberg