ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: static final string.
Date Fri, 28 Sep 2001 07:30:59 GMT
On Fri, 28 Sep 2001 16:17, Tarun Garg wrote:
> 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);
>     }
> }

Theres no clean way to do it as it will get inlined in other class. You could 
wrap the constant in another object (because the other object wont be 
inlined). You could also put in ugly hacks like one of

class B
{
  private static Class CLASS_HACK_REF = A.class;
}

or perhaps make it runtime final like

class A
{
  public static final String mesg = 
    System.getProperty( "some.key.that.not.exist", "hello" );
}

or just do clean builds all the times when you notice such changes.

-- 
Cheers,

Pete

----------------------------------------------------------------
Fools ignore complexity.  Pragmatists suffer it.
Some can avoid it.  Geniuses remove it.
-- Perlis's Programming Proverb #58, SIGPLAN Notices, Sept. 1982
----------------------------------------------------------------

Mime
View raw message