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.

Default methods aren't skipped

See original GitHub issue

Interfaces can have default methods since Java 8. There was an attempted code fix to ignore them in the FactoryProvider: https://github.com/google/guice/commit/85f14e03ee00b20e20fd0f018a00ef52fcf909b1

However, the fix doesn’t work because the condition needs to be || instead of &&. (Default methods aren’t synthetic or bridge)

This makes it so that if you call any default method in an interface, you end up with the Guice-provided method instead of the default one.

public interface FooFactory {
    Foo create();

    default Foo createWithData(Data data){ 
        Foo foo = create();  // This will never be called, even if you call `fooFactory.createWithData(data)`
        foo.addData(data);
        return foo;
    }
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
nathanmerrillcommented, May 23, 2017

You mention skipping non-bridge/synthetic default methods may be backwards incompatible: I’m struggling to come up with a use-case of somebody writing a default method, but wanting it to be overridden by Guice.

That said, assuming that there is a use-case, I think it would it be possible to use some annotation to indicate to “skip this method”? I’m not a huge fan of introducing an entirely new annotation for a small edge case as this, but I think it would work.

0reactions
badbobcommented, Feb 27, 2020

Is there are any progress on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No need to hate Java default methods - Mike my bytes
Yes, default methods do introduce a notion of multi inheritance, but also cleverly avoid almost all the issues with such an approach. Unlike ......
Read more >
When delegating interface implementation, default methods ...
When delegating interface implementation, default methods aren't overridden ; KT-31584 Delegation to a Java class misses overrides ; KT-36903 Start delegating to ...
Read more >
java - Why can't unrelated default methods from interfaces be ...
I have two Interfaces that have the same default methods which are then both implemented by a class like this: public interface I1...
Read more >
Could we avoid default method interfaces in Java at least in ...
I have noticed that the default methods got higher and higher adoption in the ExoPlayer library. The problem is that not every build ......
Read more >
Can We Override Default Method in Java? - GeeksforGeeks
It is not mandatory to override the default method in Java. If we are using Only one interface in a Program then at...
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