Re: why doesn't this work? final assignments and switches

From: Roedy Green (see_at_mindprod.com)
Date: 04/18/04


Date: Sun, 18 Apr 2004 02:15:30 GMT

On Sat, 17 Apr 2004 19:46:18 -0400, xaos <xaos@aol.net> wrote or
quoted :

>case A0:
>// compiler complains:
>// constant expression required
>// but isn't A0 etc constant ?

switch cases want [values known at compile time. Yours are not known
until the class is instantiated.

try static final A0 = 0;

But if you are calling them A0, why not just say 0?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming. 
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Relevant Pages

  • Re: inline power function replacement
    ... switch ) ... and the order of the cases should not matter if the compiler ... the absolutely least overhead for the vast majority of cases. ... roughly the same overhead as an indirect function call (calling through ...
    (comp.lang.c)
  • Re: I dont understand enums
    ... Eclipse complaining that "case expressions must be constant expressions". ... which means *compile time* constants. ... you might recompile PlaylistType ... However, you can switch on enums too, so change the switch to do ...
    (comp.lang.java.programmer)
  • Re: Case expression must be constant expression
    ... It is sometimes possible for an instance constant to be evaluated at compile time. ... Btw, I wanted to use a switch in my code, but due to these limitation it's now a if/else stack... ... While there are *some* times when a switch is appropriate, I've found that I haven't used a switch statement once I understood the State, Strategy, and Flyweight patterns. ...
    (comp.lang.java.programmer)
  • Re: inline power function replacement
    ... switch ) ... and the order of the cases should not matter if the compiler ... the absolutely least overhead for the vast majority of cases. ... roughly the same overhead as an indirect function call (calling through ...
    (comp.lang.c)
  • Re: Form navigation
    ... You're calling Hide and then setting it to null? ... I have implemented a simple function in Program.cs to switch ... Here is the function I am using to switch screens: ... Form oldFrm) ...
    (microsoft.public.dotnet.framework.compactframework)