ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@socket.net
Subject Re: static final string.
Date Sat, 29 Sep 2001 02:04:00 GMT
The simplest solution seems to be 

public static final String mesg = new String( "hello" );

This will not have a value at compile time, and so the String will not be 
inlined.

At 05:30 PM 9/28/2001 +1000, you wrote:
>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