> You'd still have to recompile all code to take advantage of that.

Er, no you don't. The value of the constant is only set when the class is
loaded. It will use the current value of the system property, which gets
set when the JVM is initialized, i.e. before any classes get loaded.
Anything that was compiled to that constant will use the value of the
constant as defined when the class is loaded. It is a hack, but it avoids
changing the API...

For example:

public interface MySysProps {
      String CONST = System.getProperty("myprop", "default");
}

public class SysPropsTest {
      public static void main(String[] args) {
            System.out.println("Value of constant: " + MySysProps.CONST);
      }
}

Output:

C:\>java SysPropsTest
Value of constant: default

// no need to recompile, just run with a new value:

C:\>java -Dmyprop=foobar SysPropsTest
Value of constant: foobar

--
Colin Sharples


CAUTION - This message may contain privileged and confidential information 
intended only for the use of the addressee named above. If you are not the 
intended recipient of this message you are hereby notified that any use, 
dissemination, distribution or reproduction of this message is prohibited. If 
you have received this message in error please notify Bank of New Zealand 
immediately. Any views expressed in this message are those of the individual 
sender and may not necessarily reflect the views of Bank of New Zealand.

Reply via email to