Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14876
| From | Lew <noone@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How are multiple Java files compiled together? |
| Date | 2012-05-28 22:56 -0700 |
| Organization | albasani.net |
| Message-ID | <jq1od6$8bu$1@news.albasani.net> (permalink) |
| References | <90a3f6ec-dfd4-472b-866d-98eaa92364d5@googlegroups.com> <ush5s7losci9deken8k09qpbia9nqku6s5@4ax.com> <7im6s7leho1fhnqd28lcbmpg7c18hbj2hi@4ax.com> |
Roedy Green wrote: >> 3. It can compare the dates on the class file and corresponding *.java >> file. If the *.java file is newer it knows to recompile. >> see http://mindprod.com/jgloss/javac.html > > There is a gotcha. > If have a static final constant X in class A. I think it applies to instance and local constants also. > Class B references X. > > You modify the value of X. > > The compeller will be smart enough to recompile A, but not B. It > should recompile B, because of constant inlining. "Should"? What do you mean by that? The constant, by virtue of it being a constant, is in the B class as a constant. It is not a reference because it's a constant. Class B has no way of knowing that the constant once had a label in another class. Because it's a constant. That's the way it is. I do not express an opinion on how it should be. The JLS does explain why that is, though. > When you update non-private constant values, do a clean compile of > everything to get the inlined constant values propagated. We create non-private constants, but we really aren't supposed to. "Other than for true mathematical constants, we recommend that source code make very sparing use of class variables that are declared static and final. If the read-only nature of final is required, a better choice is to declare a private static variable and a suitable accessor method to get its value." <http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9> BTW, public, don't confuse constants with "static final" variables. Only some of the latter are the former, and some of the former are not the latter. The JLS doesn't restrict the definition of "constant variable" to static variables, or even member variables. <http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.4> "A variable of primitive type or type _String_, that is _final_ and initialized with a compile-time constant expression (§15.28), is called a /constant variable/." One of the implications: "One other thing to note is that static final fields that have constant values (whether of primitive or String type) must never appear to have the default initial value for their type (§4.12.5). This means that all such fields appear to be initialized first during class initialization (§8.3.2.1, §9.3.1, §12.4.2)." [op. cit.] -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
How are multiple Java files compiled together? Jason Kim <iamjsonkim@gmail.com> - 2012-05-27 15:48 -0700
Re: How are multiple Java files compiled together? Knute Johnson <nospam@knutejohnson.com> - 2012-05-27 16:34 -0700
Re: How are multiple Java files compiled together? Jason Kim <iamjsonkim@gmail.com> - 2012-05-27 16:47 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-27 20:18 -0700
Re: How are multiple Java files compiled together? Knute Johnson <nospam@knutejohnson.com> - 2012-05-27 21:08 -0700
Re: How are multiple Java files compiled together? Gene Wirchenko <genew@ocis.net> - 2012-05-28 09:32 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-28 22:35 -0700
Re: How are multiple Java files compiled together? Gene Wirchenko <genew@ocis.net> - 2012-05-29 09:20 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-27 17:35 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-27 19:34 -0700
Re: How are multiple Java files compiled together? Roedy Green <see_website@mindprod.com.invalid> - 2012-05-28 04:00 -0700
Re: How are multiple Java files compiled together? Lew <noone@lewscanon.com> - 2012-05-28 22:56 -0700
csiph-web