• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

:( one more stupid misstake, pls help me !

 
Hiep Nguyen
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my real code:

if i open one of two comments or open two comments, when compile, it has these error
[error]
gui/Stupid.java [21:1] duplicate case label
case Define.CMD_DETAIL_GROUP:
^
gui/Stupid.java [34:1] duplicate case label
case Define.CMD_DETAIL_GROUP:
^
2 errors
Errors compiling Stupid.
[/errors]
i already check, but i don't why it has the error. do you have the error? my code stupid or my JVM is stupid?
thanks !
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any field defined in an interface must be static and final. Since CMD_ADD_GROUP and CMD_DETAIL are declared in the 'Define' interface, they are therfore implicity static and final (even though you didn't have to write out the keywords).
Java compilers inline static final constants. As an illustration:

Here's a slightly off-topic digression that you may read or ignore as you like:
Constant inlining is actually something to be careful of when you're writing libraries for other developers to use from their code. Suppose you distributed fancyLogger-1.0.jar with this declaration:

I compiled against that version. Then you write a new version, fancyLogger-2.0.jar:

If I drop fancyLogger-2.0.jar next to my code (compiled agains fancyLogger-1.0.jar), the logging will be messed up. My compiled code treats WARN as 0 and ERROR as 1 -- the only way to change that is to recompile. When I try to run the incompatable versions, where I wanted ERROR I'll get WARN. Where I wanted WARN, I'll probably get an error claiming there is no such constant as 0.
That was a long-winded way of explaining something that isn't too complex.
Back on topic:
The is probably a mistake, but CMD_ADD_GROUP and CMD_DETAIL are both assigned the value 10.

Is treated by the compiler as

You probably wanted CMD_DETAIL_GROUP to equal 13, not 10.
[ February 19, 2003: Message edited by: David Weitzman ]
 
Hiep Nguyen
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh! i'm really stupid , because my code so long so i have a misstake, and i also don't careful when post the short code.
thank you so much!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic