Path: csiph.com!au2pb.net!feeder.erje.net!2.eu.feeder.erje.net!nntpspool01.opticnetworks.net!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: about class dependancies Date: Wed, 2 Dec 2015 21:58:08 -0500 Organization: Aioe.org NNTP Server Lines: 76 Message-ID: References: <565f816b$0$3054$426a74cc@news.free.fr> <77dedcc2-f07c-4234-9b5c-22993b04c6d1@googlegroups.com> <565f9194$0$4565$426a74cc@news.free.fr> <565f9a2e$0$3878$426a74cc@news.free.fr> NNTP-Posting-Host: 1lM8B9/qdtKBc/uIRK2Gjw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:33287 On 12/2/2015 9:55 PM, Arne Vajhøj wrote: > On 12/2/2015 8:26 PM, regis wrote: >> On 12/03/15 02:05, Stefan Ram wrote: >>> regis writes: >>>> It still seems to work if it is made final... >>> >>> echo >A.java public final class A { public static void main( final >>> java.lang.String[] args ){ java.lang.System.out.println( B.x ); }} >>> echo >B.java public final class B { public static final int x = 1; } >>> javac A.java >>> javac B.java >>> java A >>> RENAME A.class hide.class >>> echo >B.java public final class B { public static final int x = 2; } >>> javac B.java >>> DELETE A.class >>> RENAME hide.class A.class >>> java A >>> >>> Now it still prints 1, not 2. >>> >>> The above script assume Microsoft® Windows. >>> You might have to adjust it for your environment. >> >> Ah, interesting... >> so a non-updated file A.class can indeed be tricked by a change in B... > > What is happening is seen with this: > > public class B { > public static final int K = 123; > } > > public class A { > public static void main(String[] args) { > System.out.println(B.K); > System.out.println(123); > } > } > > C:\Work>javap -c A > Compiled from "A.java" > public class A { > public A(); > Code: > 0: aload_0 > 1: invokespecial #1 // Method > java/lang/Object."init>":()V > 4: return > > public static void main(java.lang.String[]); > Code: > 0: getstatic #2 // Field > java/lang/System.out:Ljava/io/PrintStream; > 3: bipush 123 > 5: invokevirtual #4 // Method > java/io/PrintStream.println:(I)V > 8: getstatic #2 // Field > java/lang/System.out:Ljava/io/PrintStream; > 11: bipush 123 > 13: invokevirtual #4 // Method > java/io/PrintStream.println:(I)V > 16: return > } > > A.class does not contain a named reference to B.K instead > A.class contains the while of B.K from the time of compilation. Note that the practical impact of this is close to zero. Practically everyone starts a Java build by deleting all the previously build class files. Arne