I have a problem with deferred binding or perhaps GWT's static analysis not 
behaving quite the way I thought it did. I have a class that looks like this:

public abstract class Mode
{
    public abstract boolean isDebug();
}

and I have two subclasses, one with a hard-coded value of false for isDebug() 
and the other has a hard-coded value of true. I then have appropriate gwt.xml 
directives that introduce a new permutation and select the appropriate 
implementation of Mode.

This all works as expected. My problem is this...if I use a central class to 
record whether we're in debug mode or not like this:

public class Central
{
    private static final Mode mode = GWT.create(Mode.class);

    public static boolean isDebug() { return mode.isDebug(); }
}

and then I have a class that uses this value like this:

public class Foo
{
    public void doSomething()
    {
        if (Central.isDebug())
            Log.debug("Here I am");
    }
}

then what I find is that in the permutation where isDebug() returns false, the Log.debug("Here 
I am") line does not get run, but the text string "Here I am" is in the output 
javascript file for *all* permutations. I was expecting it only to be in the debug permutations.

If I change the Foo class like this:

public class Foo
{
    private static final Mode mode = GWT.create(Mode.class);

    public void doSomething()
    {
        if (mode.isDebug())
            Log.debug("Here I am");
    }
}

then I find that the "Here I am" string is only in the debug permutations.

Am I expecting too much of the static analysis GWT does at compile time? Or 
have I missed something?

Thanks,
Paul

--
You received this message because you are subscribed to the Google Groups "Google 
Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to