Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Mike Amling Newsgroups: comp.lang.java.programmer Subject: Re: about class dependancies Date: Mon, 21 Dec 2015 08:29:12 -0600 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <565f816b$0$3054$426a74cc@news.free.fr> <77dedcc2-f07c-4234-9b5c-22993b04c6d1@googlegroups.com> <565f9194$0$4565$426a74cc@news.free.fr> <31f29220-8f05-42a4-b62e-59eec378b924@googlegroups.com> <5fa6a8a6-389b-4ed0-ae37-941d5fd6d358@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 21 Dec 2015 14:25:41 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="5c7a52e8d8bef31920cedcbb61c44150"; logging-data="7150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rmUDFSyrwejIrwui58fng" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: <5fa6a8a6-389b-4ed0-ae37-941d5fd6d358@googlegroups.com> Cancel-Lock: sha1:Bg6nq2BoA7tegy57WZZIGLIDHOw= Xref: csiph.com comp.lang.java.programmer:33379 On 12/17/15 3:36 PM, Lew wrote: > > You define a constant variable in B and refer to it from A. > > You recompile B with a different constant value. > > You then run A without recompiling it. Magically, it refers to the old value of the B constant. > > Because the constant was inlined in A, it stopped looking like a variable, so the runtime linkage doesn't refer to the constant from B, but uses the inlined value already in A. > http://javasplitter.blogspot.com/2011/10/static-final-inline-trap.html I've seen Java software use this to ensure that the components in use are consistent. E.g., class A { public static final int VERSION=3; public int getVersion() { return VERSION; } } class B { public static void main(String[] args) { if (A.getVersion() // The version we're running with !=A.VERSION) { // The version we were compiled with uhoh(); } } } Mike Amling -- QnV0IEkgZG9uJ3QgcmVjYWxsIHdoYXQgcHJvZ3JhbSBJIHNhdyB0aGlzIGluLg==