ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tarun Garg" <tar...@induslogic.com>
Subject Re: static final string.
Date Fri, 28 Sep 2001 07:32:34 GMT
The java language specification(13.4.8) answers my question.
Maybe somebody else can gain from it too.
I reproduce the following from the specs.
.....
The best way to avoid problems with "inconstant constants" in
widely-distributed code is to declare as compile time constants only values
which truly are unlikely ever to change. Many compile time constants in
interfaces are small integer values replacing enumerated types, which the
language does not support; these small values can be chosen arbitrarily, and
should not need to be changed. Other than for true mathematical constants,
we recommend that source code make very sparing use of class variables that
are declared static and final. If the read-only nature of final is required,
a better choice is to declare a private static variable and a suitable
accessor method to get its value. Thus we recommend:


private static int N;
public static int getN() { return N; }

rather than:

public static final int N = ...;

...........

----- Original Message -----
From: "Tarun Garg" <tarung@induslogic.com>
To: <ant-user@jakarta.apache.org>
Sent: Friday, September 28, 2001 12:15 PM
Subject: Re: static final string.


> The java language itself specifies this behaviour.
> So I guess nothing much can be done about this.
>
> ----- Original Message -----
> From: "Tarun Garg" <tarung@induslogic.com>
> To: "ant" <ant-user@jakarta.apache.org>
> Sent: Friday, September 28, 2001 11:47 AM
> Subject: static final string.
>
>
> > This probably is not exactly an ant issue, but some of you might have
> faced
> > it that's why I am posting it here.
> > I have two classes. A and B.
> > class A has a member in it which is declared something like:
> >
> > public static final String mesg="hello";
> >
> > Now class B uses this string for some purpose of its own.
> > Lets say it just prints the message.
> > class B {
> > public static void main(String args[])
> >     {
> >         System.out.println(A.mesg);
> >     }
> > }
> >
> > Now when I change the mesg in class A to "hello world", Ant recompiles
> only
> > the class A as A.java is the only file that has been modified.
> > Now when I run class B, the message still remains "hello".
> > I believe this has something to do the way compilers are implemented. I
> > tried both javac and jikes. Both exhibit the same behaviour.
> > During development it can happen that you need to change your final
> > variables too.
> > Has anybody faced this problem before ? How do you solve it ?
> > One solution would be that whenever somebody changes a final variable,
she
> > informs everybody working on that project to do a clean build.
> > But that's not a very clean solution.
> > Any tips ?
> >
> >
>


Mime
View raw message