google / google/guice

cannot override guice 2.0 provider method

Open
#347 6 comments 0 reactions 0 assignees View on GitHub
imported Priority-Low
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [ferncam1](https://code.google.com/u/102290260414172705059/) 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_

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.