Search code examples
javaguice

Why do we need to implement configure() in Guice Modules?


I am having the following code:

public class XYZModule extends AbstractModule {

    @Override
    protected void configure() {
    }

    @Provides
    @Singleton
    private XYZ provideXYZ() {
        return new XYZ(1, 2);
    }
}

Does empty configure() method serve any purpose here?


Solution

  • You don't need it anymore

    Since Guice 4.2, the configure() method isn't abstract anymore. So you can get rid of it in your modules if you don't use it. Here's what the release notes say about it:

    AbstractModule.configure() is non-abstract to allow modules with only @Provides/@ProvidesIntoSet/... methods.