ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Les Hughes <leslie.hug...@rubus.com>
Subject RE: static final string.
Date Fri, 28 Sep 2001 13:56:53 GMT
Externalise your strings into resouce bundles then nothing needs to be
rebuilt if you change your constants :-)

> -----Original Message-----
> From: Peter Donald [mailto:donaldp@apache.org]
> Sent: 28 September 2001 08:31
> To: ant-user@jakarta.apache.org
> Subject: Re: static final string.
> 
> 
> 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