Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling From Command Line Wth Circular Dependencies

Imagine that I have two classes (shown below). Now imagine that I am compiling them using javac.exe from the command line. They won't compile because class A needs class B's methods to exist and vice versa. Is there any trick to getting them to compile from the command line? (Eclipse can compile this no problems!)

I should add they are both currently in two separate .java files.

public class A {
    public void doAWork() { /* A work goes here. */}
    public void doBWork() { new B().doBWork(); }
}
public class B {
    public void doBWork() { /* B work goes here. */}
    public void doAWork() { new A().doAWork(); }
}
like image 553
John Fitzpatrick Avatar asked Sep 04 '26 06:09

John Fitzpatrick


1 Answers

It looks like your issue is elsewhere.

I can perfectly compile the code in Java 1.5, 1.6 and 1.7 with the following command:

javac A.java B.java

Even providing a single file name works perfectly, since B.java is in the same directory:

javac A.java

Are you sure the two files are placed in appropriate directories?

like image 58
AbdullahC Avatar answered Sep 05 '26 20:09

AbdullahC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!