Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: about class dependancies Date: Thu, 17 Dec 2015 08:39:07 +0000 Organization: A noiseless patient Spider Lines: 71 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> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="1d47646cb42a54284bd577b6100d82bd"; logging-data="23813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IurUTr9vMRnftdBFS00lAF6x92XJpMhQ=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <31f29220-8f05-42a4-b62e-59eec378b924@googlegroups.com> Cancel-Lock: sha1:EF/gI05VUK41XXzvWs75f1zJQYY= Xref: csiph.com comp.lang.java.programmer:33361 On 17/12/15 02:27, Lew wrote: > On Wednesday, December 2, 2015 at 4:49:41 PM UTC-8, regis wrote: >> On 12/03/15 01:32, Lew wrote: >>> On Wednesday, December 2, 2015 at 3:40:46 PM UTC-8, regis wrote: >>>> let say we have some public class A >>>> that depends on some public class B, e.g.: >>>> >>>> ==== >>>> // B.java >>>> public class B { >>>> public int f(int n) { return 2*n; } >>>> } >>>> ==== >>>> // A.java >>>> public class A { >>>> public static void main (String[] args) { >>>> B b= new B (); >>>> System.out.println (b.f(5)); >>>> } >>>> } >>>> ==== >>>> $ javac A.java B.java >>>> $ java A >>>> 10 >>>> ==== >>>> >>>> Then let say class B changes (with signature of f() unchanged), e.g.: >>>> >>>> ==== >>>> // B.java, changed >>>> public class B { >>>> int lambda= 10; >>>> public int f(int n) { return lambda*n; } >>>> } >>>> ==== >>>> >>>> Finally, we update file B.class, but not file A.class, >>>> >>>> ==== >>>> $ javac B.java # but not A.java >>>> $ java A >>>> 50 >>>> ==== >>>> >>>> It seems to work, but is it guaranteed ? >>>> or should file A.class still be updated ? >> >>> The Java compiler "javac" is smart enough to resolve many dependencies, including the one you note here. >>> However, this would not work if 'lambda' (*terrible* name for that variable!) were made 'final', and therefore a constant variable. >> >> It still seems to work if it is made final... >> >> // B.java, changed >> public class B { >> final int multiplier= 1000; >> public int f(int n) { return multiplier*n; } >> } >> ==== >> $ javac B.java # but not A.java >> $ java A >> 5000 > That isn't what I meant. I meant if you recompile 'A' but not 'B" then you don't pick up the change in 'B'. What you did was recompile 'B' and run 'A'. I had misread your example. I don't get it. A.java refers to B, so compiling A.java will also compile B.java as an implicit class, unless you have implicit compilation turned off. -- ss at comp dot lancs dot ac dot uk