Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8307
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: borrowing Constants |
| Date | 2011-09-25 11:36 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <26695994.492.1316975792589.JavaMail.geo-discussion-forums@prec11> (permalink) |
| References | <cf9q77h3gnhunlqpckpsobog4oqvlhiga7@4ax.com> <4e7d27e8$0$290$14726298@news.sunsite.dk> <86afq.26627$CY4.6386@newsfe04.iad> <02dq77p0i00lsfdsl78bfnencd2ab4a5gs@4ax.com> <OmKfq.28055$GV2.4668@newsfe20.iad> |
On Sunday, September 25, 2011 11:25:49 AM UTC-7, Daniel Pitts wrote:
> Roedy Green wrote:
>> 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;
Compile-time constant.
> VERSION = SomeOtherClass.calculateVersionNumber();
Not a compile-time constant.
They are treated differently.
> }
> }
>
> public class UsesOtherClass {
> public static final VERSION = MyConstants.VERSION;
> }
>
> When UsesOtherClass is initialized, it requires MyConstants *and*
> SomeOtherClass to be initialized.
But it compiles the compile-time constant in at compile time (hence the name, "compile-time" constant - amazing connection, eh?), so it doesn't need the source class at run time for that constant.
> In general, if you use some code, you are transiently using its
> dependencies as well.
The exception being compile-time constants.
> 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).
More precisely, it's *compile-time* constants that get special treatment. People bandy about the term "constant" very carelessly.
Compile-time constants are bound in at compile time (the logic is compelling) as as literals. The surprising behaviors come at runtime from version mismatches and from the fact that transitive class dependencies are hidden by the compile-time constants having been bound at compile time.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
borrowing Constants Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 17:40 -0700
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-23 20:44 -0400
Re: borrowing Constants Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-23 22:10 -0300
Re: borrowing Constants Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 18:39 -0700
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-23 22:17 -0400
Re: borrowing Constants Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-09-25 11:25 -0700
Re: borrowing Constants Lew <lewbloch@gmail.com> - 2011-09-25 11:36 -0700
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-23 22:30 -0400
Re: borrowing Constants Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-23 21:15 -0400
Re: borrowing Constants Roedy Green <see_website@mindprod.com.invalid> - 2011-09-23 18:43 -0700
Re: borrowing Constants markspace <-@.> - 2011-09-23 18:44 -0700
Re: borrowing Constants Lew <lewbloch@gmail.com> - 2011-09-23 19:19 -0700
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-23 22:32 -0400
Re: borrowing Constants Lew <lewbloch@gmail.com> - 2011-09-23 19:11 -0700
Re: borrowing Constants Lew <lewbloch@gmail.com> - 2011-09-23 19:26 -0700
Re: borrowing Constants v_borchert@despammed.com (Volker Borchert) - 2011-09-24 09:44 +0000
Re: borrowing Constants Roedy Green <see_website@mindprod.com.invalid> - 2011-09-24 15:38 -0700
Re: borrowing Constants Roedy Green <see_website@mindprod.com.invalid> - 2011-09-24 17:09 -0700
Re: borrowing Constants Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-24 20:14 -0400
Re: borrowing Constants markspace <-@.> - 2011-09-24 18:18 -0700
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-25 22:36 -0400
Re: borrowing Constants Arne Vajhøj <arne@vajhoej.dk> - 2011-09-25 22:35 -0400
Re: borrowing Constants Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-09-26 01:22 +0200
csiph-web