John Fitzpatrick
John Fitzpatrick

Reputation: 4349

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(); }
}

Upvotes: 3

Views: 1106

Answers (1)

AbdullahC
AbdullahC

Reputation: 6730

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?

Upvotes: 4

Related Questions