Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe20.iad.POSTED!83aa503d!not-for-mail From: Daniel Pitts User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: borrowing Constants References: <4e7d27e8$0$290$14726298@news.sunsite.dk> <86afq.26627$CY4.6386@newsfe04.iad> <02dq77p0i00lsfdsl78bfnencd2ab4a5gs@4ax.com> In-Reply-To: <02dq77p0i00lsfdsl78bfnencd2ab4a5gs@4ax.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 42 Message-ID: X-Complaints-To: abuse@newsrazor.net NNTP-Posting-Date: Sun, 25 Sep 2011 18:25:50 UTC Date: Sun, 25 Sep 2011 11:25:49 -0700 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8305 On 9/23/11 6:39 PM, Roedy Green wrote: > On Fri, 23 Sep 2011 22:10:28 -0300, Arved Sandstrom > wrote, quoted or indirectly quoted > someone who said : > >> Which logical place is not in the code at all. Granted, I don't know >> that Roedy's example is doing anything more than using "VERSION" as a >> generic variable name (I hope). > > I chose it as an easy-to-understand example. In my example, VERSION > is something you might display in a an About box. > > The question is really about accidentally dragging in some giant class > when you had no intention of using its code. If you are using a field from it, you *are* using its code. Imagine the following scenario: public class MyConstants { public static final String VERSION; public static final int ZERO; static { ZERO = 0; VERSION = SomeOtherClass.calculateVersionNumber(); } } public class UsesOtherClass { public static final VERSION = MyConstants.VERSION; } When UsesOtherClass is initialized, it requires MyConstants *and* SomeOtherClass to be initialized. In general, if you use some code, you are transiently using its dependencies as well. Although, I thought I read somewhere that constants can sometimes be inlined (which can lead to other surprising behaviors if you recompile only some of your classes on make).