Im wondering if it is possible to create this object based on the code below or is it a cyclic dependency which cant be solved?
public class A {
private B b;
public A(B b) {
this.b = b;
}
public class B {
public B() {}
}
}
I was provided with a class which looked like this and I cant find a way to initialize B or A. Its like and impossible cycle.
If all you do with instance of
BinA's constructor is an assignment, then you could try usingnullat instantiation and then hand it aBinstance:the above requires
a.bto be public, or you need to add a setter. But that looks bad to me, so perhaps you should makeBclass static, and by doing so it can be instantiated independently ofA::and then