gpt4 book ai didi

java - 尽管 .class 已经更新,为什么 javac 仍重新编译我的 .java?

转载 作者:行者123 更新时间:2023-12-02 09:49:19 26 4
gpt4 key购买 nike

我被告知 javac 足够聪明,它不会重新编译 .java,前提是这个 .java 有时间戳在 .class 之前。我只是发现它在我的机器上不起作用,我肯定在某个地方错了吗?

我的P.java位于.../eg/access下,其中P.java声明为access

eg 
|- access
|- P.class
|- P.java

然后,当我运行javac P.java时,每次都会重新编译,这是正常的还是我错了?

最佳答案

默认情况下,Javac 每次都会重新编译所有内容。您观察到的行为是正确的,并且是有意设计的。

看起来您可以为此行为指定一个选项:

-Xprefer:{newer,source}

Specify which file to read when both a source file and class file are found for a type. (See Searching For Types). If -Xprefer:newer is used, it reads the newer of the source or class file for a type (default). If the -Xprefer:source option is used, it reads source file. Use -Xprefer:source when you want to be sure that any annotation processors can access annotations declared with a retention policy of SOURCE.

取自:http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html

您可能还会想到 Eclipse 的编译器,我很确定它确实会进行增量编译 - 或者 ant 中的 javac 任务,它足够智能来找出此类情况。

关于java - 尽管 .class 已经更新,为什么 javac 仍重新编译我的 .java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8271282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com