I have two java class files. Each of them has methods the other one uses.
public class class1{
class2 c2 = new class2();
m1(){
c2.ma();
m2();
}
m2(){}
}
public class class2{
class1 c1 = new class1();
ma(){}
mb(){
c1.m2();
}
}
The lines
class1 c1 = new class1();
and
class2 c2 = new class2();
refer to each other causing an infinite loop, resulting in a java.lang.StackOverflowError error.
Is there some way to have the classes refer to each other or do I have no choice but to transfer all of my methods into a single class?
StackOverflowErroris due to a a cyclic constructor call.