Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.glorb.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Sun, 25 Sep 2011 22:35:43 -0400 From: =?ISO-8859-1?Q?Arne_Vajh=F8j?= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: borrowing Constants References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 40 Message-ID: <4e7fe4ff$0$288$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 72.192.23.141 X-Trace: news.sunsite.dk DXC=Xgie<_0AKafN2]LRcf6HDcYSB=nbEKnkkRaZ^n=XfmbgJPe3\kP5EUaKBm9cfh9BSdM2;kT<[:>[a5QQFc1jbKHcoW]INE2]F@o X-Complaints-To: staff@sunsite.dk Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8322 On 9/24/2011 8:09 PM, Roedy Green wrote: > On Fri, 23 Sep 2011 17:40:20 -0700, Roedy Green > wrote, quoted or indirectly quoted > someone who said : > >> class A >> { >> static String VERSION = "1.0b"; >> } >> >> and >> class B >> { >> static String VERSION = A.VERSION; >> } > > restating, if the expression for A.VERSION cannot be evaluated an > compile time, even final won't rescue you from having to include both > A in your jar and indirectly loading A when you load B. > > So the rule of thumb use static final with values known at compile > time to avoid needless class loading. But be aware, you must recompile > B if the value of A.VERSION changes, or you will get the old value. > > Another rule of thumb may be, instead of cross linking classes with > references to each others constants, refactor out the constants to a > third class, and reference it or extend it. > > In a number of my projects I have a Config class where everything > constant (possibly computed) needed to configure a program for a > particular use are collected. Rule of thumb: don't worry about the microseconds spend on class initialization and spend the time on something relevant. The requirement to recompile B if A is changed for constants can be a much more severe problem than class init. Arne