Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calendar.MONTH returns 2 its March now



Date: Thu, 24 Mar 2005 12:06:58 -0700
From: Greg Guerin <email@hidden>
Subject: Re: Calendar.MONTH returns 2 its March now
To: email@hidden
Message-ID: <l03130301be68b8e4d1c9@[216.190.249.206]>
Content-Type: text/plain; charset="us-ascii"

All the named Calendar constants, not just months, are defined as:
  public final static int <NAME> = <int constant here>;

That means a Java compiler is free to inline them as literal constants into
any class that references them by name. So if your class Foo has this:
int bar = Calendar.FEBRUARY + 1;


Note that all primitive types, along with Strings, having 'static final'
qualifiers can be compile-time literals and thus subject to inlining. And
there's no way to tell the compiler to NOT inline such constants. It
arguably has to, in order for 'case' to work (see JLS on 'case'-value
constraints).

the JLS is more specific than that. such constants *must* be inlined. it's mentioned in various places, but primarily in chapter 13, "Binary Compatibility". for example:


References to fields that are final and initialized with compile-time constant expressions are resolved at compile time to the constant value that is denoted. No reference to such a constant field should be present in the code in a binary file (except in the class or interface containing the constant field, which will have code to initialize it), and such constant fields must always appear to have been initialized; the default initial value for the type of such a field must never be observed.

--
Elliott Hughes, http://www.jessies.org/~enh/

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.