Tuesday, 13 August 2013

Java Circular Reference - Can’t Compile

Java Circular Reference - Can't Compile

File: A.java
class A
{
B b;
public A() {
b = new B();
}
}
File: B.java
class B
{
public B() {}
public foo(A a) {...}
}
The above code can not be compiled because A needs B before it can compile
and B needs A before it can compile. Neither shall compile before the
other. Now what?
This example is trivial. I could remove foo(A a) {...} such B.java would
compile. Then compile A.java. Restore B.java then compile it. But I'm
trying to build RXTX from source and its dependencies are a maze of twisty
little phrases.
I had hoped that I could compile to non-working class code. Then with all
the classes and methods defined compile again into working code.
Is there a magic bullet?

No comments:

Post a Comment