frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Injector#getBinding does not handle primitives the same way as Injector#getInstance #116

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Guice seems treat primitives and their capital-letter counterparts
inconsistently.

  public void testInjectorHandlesPrimitivesConsistently() {
    Injector inj = Guice.createInjector(new AbstractModule() {
      protected void configure() {
        bind(int.class).toInstance(1984);
      }
    });
    assertEquals(1984, (int)inj.getInstance(int.class)); // pass
    assertEquals(1984, (int)inj.getInstance(Integer.class)); // pass
    assertEquals(1984, (int)inj.getInstance(Key.get(int.class))); //pass
    assertEquals(1984, (int)inj.getInstance(Key.get(Integer.class))); //pass
    assertNotNull(inj.getBinding (Key.get(int.class)));  //pass
    assertNotNull(inj.getBinding(Key.get(Integer.class)));  //fail
  }

Shouldn't the injector return the same binding for both Key.get(int.class)
and Key.get(Integer.class)?

Original issue reported on code.google.com by jmour...@gmail.com on 15 Jun 2007 at 8:59

GoogleCodeExporter commented 9 years ago
I'm going to fix this for 2.0:
http://publicobject.com/2008/06/integerclass-and-intclass-as-guice-keys.html

Original comment by limpbizkit on 1 Jun 2008 at 9:02

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 6 Jun 2008 at 4:44