Skip to content

Java 8: Static interface methods considered with FactoryModuleBuilder #937

Closed

Description

@kchung-rmn

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.

Activity

  1. sameb commented on Jun 27, 2015

    @sameb
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址