简体   繁体   English

从命令行编译Wth循环依赖项

[英]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. 现在假设我正在使用命令行中的javac.exe编译它们。 They won't compile because class A needs class B's methods to exist and vice versa. 它们不会编译,因为A类需要B类的方法存在,反之亦然。 Is there any trick to getting them to compile from the command line? 有没有任何技巧让他们从命令行编译? (Eclipse can compile this no problems!) (Eclipse可以编译这个没问题!)

I should add they are both currently in two separate .java files. 我应该补充说,它们目前都在两个独立的.java文件中。

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

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: 我可以使用以下命令在Java 1.5,1.6和1.7中完美地编译代码:

javac A.java B.java

Even providing a single file name works perfectly, since B.java is in the same directory: 即使提供单个文件名也能完美运行,因为B.java位于同一目录中:

javac A.java

Are you sure the two files are placed in appropriate directories? 您确定这两个文件放在适当的目录中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM