Originally posted by Nitin Dubey:
I didn't quite understand what you are trying to say. Can you give an example ?
Why do we think that javac should be concerned about the internal contents of the class. Can it not be done by comparing the last modified timestamp of .java and .class ? Obviously we cannot compare the actual timestamp of the class file but we can definately store the timestamp of the java file somewhere inside the file for further comparison.
Do you think it is possible ?
Create the following three files. Now compile and run Main.java, as follows.
Now modify Settings.java and make DEBUG false.
Compile and run again:
Notice that Worker.foo is still using the old value (true) of Settings.DEBUG. This is because compile time constants get inlined in the client classes. Now, compile everything and run:
And note that the debug output no longer appears in the output. This is because *.java forced Worker.java to be recompiled. When we compiled Main.java, javac did not realize that Worker.java needs to be recompiled.