As a C programmer learning Java, I was wondering how to place
resources such as Strings in a separate file, so that it is easier to
translate or modify them globally.
    I thus used the following "resource code":

                   *** file : Resource.java ***

                   package testres;

                   public final class Resource {
                    public static final String INIT         = "Starting
...";
                    public static final String SDOWN        = "Stopping
...";
                   }

                   *** end of file : Resource.java ***

    And used a test program to call it, such as:

                   *** file : TestRes.java ***

                   package testres;

                   class TestRes {
                     public static void main (String args[]) {
                       System.out.println(Resource.INIT);
                       System.out.println(Resource.SDOWN);
                     }
                   }

                   *** end of file : TestRes.java ***

    Well, the problem is: if I change the value of a String (i.e.:
"Stopping ..." becomes "Shutting down ...") and recompile Resource.java,
it *doesn't change* anything to the result. Without any errors or
warning, I still get :

                   *** output ***

                   Starting ...
                   Stopping ...

                   *** end of output ***

    I must recompile TestRes too to get a correct result. I guess that,
as the Strings are static, their value is actually copied to the place
where they are used, thus acting more like #defines in C, and I can't
help but thinking of 'Resource.java' as an include file.
    Now, how do I know which files have to be recompiled ? I have no
explicit dependencies between files in the same package, and the only
solution is 'javac *.java' each time I change a single string !

    I guess there must be a workaround to force the calling classes to
get the actual value for the strings from the file Resource.class (where
they are too, according to a "find in files"). Probably making them
non-static will do the trick, but that seems ugly to me to allow one
class to change a Resource in another class.

    What do you think of the problem ? What advice could you give me ?

    Any help will be greatly appreciated.

        Vincent Deconinck

        Canal+ Belgium (e-mail: [EMAIL PROTECTED])


Reply via email to