3

I was unsure about "how to implement constants" in the GWT client side.

I've seen some questions about it here on stackoverflow, such as this for example, though, it talks about the enum vs static final in Java 5, and even mentions anything about GWT.

So my question is which is the most light and/or better way to implement constants in the client side of a GWT application.

Thanks.

Community
  • 1
  • 1
caarlos0
  • 20,020
  • 27
  • 85
  • 160

1 Answers1

3

Of course static final is the more light-weight than enum. However there is an issue with static final. If you compile a source importing a static final, then it is optimized, copied inside the class. This means that when you afterwards change the constant's value, that is not necessarily detected (no more import, no recompilation). That does not happen with enum, and enum has more uses. static final can be placed in an Interface, and then be abbreviated.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • hmm, I already use a interface with static final for the constants. So, this is more lightweight, but, I lost the switch-case features that I have with enums. So, i have to choose: light vs switch-case features... thanks, man! – caarlos0 Dec 16 '11 at 15:49