Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8: Static interface methods considered with FactoryModuleBuilder #937

Closed
kchung-rmn opened this issue Jun 27, 2015 · 1 comment · Fixed by #942
Closed

Java 8: Static interface methods considered with FactoryModuleBuilder #937

kchung-rmn opened this issue Jun 27, 2015 · 1 comment · Fixed by #942

Comments

@kchung-rmn
Copy link

Consider the following assisted inject factory interface:

public interface Factory {
    Impl build();

    static Factory getDefault() {
       // ...
    }
}

This is, of course, permissible in Java 8 as you can associate static methods with interfaces. However, when you use FactoryModuleBuilder on it, as so:

install(new FactoryModuleBuilder().build(Factory.class));

There is an error along the lines of the following:

Factory is an interface, not a concrete class. Unable to create AssistedInject factory.

This does not seem to be intuitive, because Factory is supposed to be an interface. Debugging this code reveals that this is in reference to the static method, which should, by all means, not be considered because of its static-ness. Indeed, FactoryProvider2's constructor does not appear to skip over static methods, as expected.

Of course, a workaround exists simply by moving the static method away from the factory interface, but this seems like a bug in the functionality of FactoryProvider2 specifically.

@sameb
Copy link
Member

sameb commented Jun 27, 2015

Yup, this seems wrong. I'll happily merge a PR that skips static methods.

@sameb sameb closed this as completed in #942 Jul 6, 2015
ShoOgino pushed a commit to ShoOgino/guiceFile that referenced this issue Oct 14, 2020
ShoOgino pushed a commit to ShoOgino/guiceMethod that referenced this issue Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants