question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should @ForOverride foo() permit super.foo() calls?

See original GitHub issue

Guava 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, where done() is sometimes final)

[*] 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:closed
  • Created 8 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cushoncommented, Jun 8, 2015

What about only allowing super.done() inside an override of done?

0reactions
eaftancommented, Jul 20, 2017
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found