Default methods aren't skipped
See original GitHub issueInterfaces 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:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top 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 >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
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.
Is there are any progress on this issue?