#347·guice

cannot override guice 2.0 provider method

Author: gissuebotCreated Jul 7, 2014Updated May 21, 2026
LabelsimportedPriority-Low

From ferncam1 on March 12, 2009 19:17:00

See the code below.  Eventhough you can successfully override a provider method with no args, overriding provider methods with more then one arg will fail.

package net.meat;

import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import com.google.inject.Provides; import com.google.inject.Singleton; import org.testng.annotations.Test;

import java.net.InetSocketAddress;

/**  *   @author Adrian Cole  / public class TestImNotCrazy {

   @Inject    InetSocketAddress me;

   @Test    void testCannotOverrideProvides() {       Injector i = Guice.createInjector(new Module2());       TestImNotCrazy crazy = i.getInstance(TestImNotCrazy.class);

   }

   static class Module1 extends AbstractModule {       protected void configure() {          // lala       }

      @Provides       @Singleton       InetSocketAddress provideMeASocket(String meat) {          return new InetSocketAddress("localhost", 80);       }    }

   static class Module2 extends Module1 {       protected void configure() {          // lala       }

      @Provides       @Singleton       @Override       InetSocketAddress provideMeASocket(String meat) {          return new InetSocketAddress("localhost", 80);       }    } }

Original issue: http://code.google.com/p/google-guice/issues/detail?id=347