google / google/guice

Default methods aren't skipped

Open
#1,104 5 comments 5 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

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;
}
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.