views:

30

answers:

1

if I inject a recursive dependency through a constructor, then it gives me an exception, while if I use setter it doesn't. Why is this?

+3  A: 

Do you mean that A has a B, and B has an A, and you're trying to inject them both into each other? Logically, the behavior you describe makes sense.

A a = new A()
B b = new B()
a.setB( b )
b.setA( a )

looks fine, but what should this look like?

A a = new A( b )
B b = new B( a )

No matter how you rewrite the second group, you can't create an A that depends on B by use of constructor.

Stefan Kendall
Thankx.......Gr8
org.life.java