Status: New
Owner: ----

New issue 693 by [email protected]: Guice provides different instances of desired type.
http://code.google.com/p/google-guice/issues/detail?id=693

Code:

===
public static class A {
    B b;
    C c;


    public A() {
        System.out.println("A");
    }

    @Inject
    public void setB(B b) {
        this.b = b;
    }

    @Inject
    public void setC(C c) {
        this.c = c;
    }
}

public static class B {
    A a;
    C c;

    public B() {
        System.out.println("B");
    }

    @Inject
    public void setA(A a) {
        this.a = a;
    }

    @Inject
    public void setC(C c) {
        this.c = c;
    }

    void foo() {
        System.out.println(System.identityHashCode(this.c));
        System.out.println(System.identityHashCode(this.a.c));
    }
}

public static class C {
    A a;
    B b;

    public C() {
        System.out.println("C");
    }

    @Inject
    public void setA(A a) {
        this.a = a;
    }

    @Inject
    public void setB(B b) {
        this.b = b;
    }
}

public static void main(String[] args) {
    Guice.createInjector(new AbstractModule() {
        protected void configure() { }
    }).getInstance(B.class).foo();
}

===

Prints:

===
B
A
C
C
A
false
1741825447
363211825
===

It means:
* classes A and B were instantiated twice
* B and A objects have different references to C

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to