从具有循环依赖关系的命令行进行编译

发布于 2024-12-24 22:57:58 字数 432 浏览 1 评论 0原文

想象一下我有两个课程(如下所示)。现在想象一下我正在从命令行使用 javac.exe 编译它们。它们不会编译,因为 A 类需要 B 类的方法存在,反之亦然。有什么技巧可以让它们从命令行编译吗? (Eclipse 可以毫无问题地编译它!)

我应该补充一下,它们当前位于两个单独的 .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(); }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦忆晨望 2024-12-31 22:57:58

看来您的问题在其他地方。

我可以使用以下命令完美编译 Java 1.5、1.6 和 1.7 中的代码:

javac A.java B.java

即使提供单个文件名也可以完美地工作,因为 B.java 位于同一目录中:

javac A.java

您确定这两个文件放置在适当的目录中吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文