Originally posted by Nitin Dubey:
Hemal,
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 ?
Cheers,
Nitin
Create the following three files. Now compile and run Main.java, as follows.
javac Main.java
java Main
Now modify Settings.java and make DEBUG false.
Compile and run again:
javac Main.java
java Main
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:
javac *.java
java Main
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.
hth.