case expressions must be constant expressions

90 views
Skip to first unread message

seven.reeds

unread,
Oct 30, 2008, 11:40:50 AM10/30/08
to Google Web Toolkit
I am not a java wizard, or even a novice it seems. I am rewriting a
app and may have out smarted myself. In the original version, in my
primary (entrypoint) class, I defined some basically global integer
constants like:

public class index
implements EntryPoint {

public final static int JOE = 0;
public final static int JED = 1;
...
}

I then used these constants all over the place as

index.JOE

even in case statements.

Ok, I have been thinking about these globals and they do not belong in
the entryPoint class. They are really part of another class. So I
have moved them into the other class definition and am referencing
them as:

index.otherClass.JOE

However, I am now getting errors of the form: "case expressions must
be constant expressions"

Is there some java syntax thingie that I am missing? Do all constants
have to be defined in the entryPoint class?

Lothar Kimmeringer

unread,
Oct 30, 2008, 12:07:30 PM10/30/08
to Google-We...@googlegroups.com
seven.reeds schrieb:

> index.otherClass.JOE
>
> However, I am now getting errors of the form: "case expressions must
> be constant expressions"

You're not following the coding style guidlines being published
by SUN, so it's hard to say. I assume that "otherClass" is not
a static inner class of class "index", but a member of type e.g.
OtherClass. So because the actual class of that member might
change (e.g. a derived class of OtherClass), the value of JOE
can change (that's the reasion why every IDE with some minimal
kind of self-respect warns you if you try that).

So you should do the following things:

- Use OtherClass.JOE instead of index.otherClass.JOE
- Go to comp.lang.java.help/programmer if you need further
help concerning the Java Programming Language rather than GWT.


Regards, Lothar

seven.reeds

unread,
Oct 30, 2008, 12:34:24 PM10/30/08
to Google Web Toolkit


On Oct 30, 11:07 am, Lothar Kimmeringer <j...@kimmeringer.de> wrote:
> seven.reeds schrieb:
>
> You're not following the coding style guidlines being published
> by SUN, so it's hard to say.[...]

lol! no disagreement on this. I'm just happy to have [mostly] working
code. Most real jave/OO coders would probably laugh themselves to
death over my code.

> So you should do the following things:
>
>  - Use OtherClass.JOE instead of index.otherClass.JOE

brilliant! this worked a treat! thanks


>  - Go to comp.lang.java.help/programmer if you need further
>    help concerning the Java Programming Language rather than GWT.

I will visit this link, I even have a few java books here but as an
old coder that comes from a time when pointers were King; Threads were
clothes or the combined fiber chains that comprised them; and, Objects
were either unidentified and flying or manifestations of nature or
function and design in the everyday tactile world -- this stuff does
not always scan. This is my cross to bear.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages