Link to home
Start Free TrialLog in
Avatar of hank1
hank1

asked on

constant expression required

UPdate to below question.  See the bug report on sunsite.  So if this is correct, how
does one create a shorthand reference to a long class name?

Some more changes?

got javac message "constant expression required" for

---file
public class A {
  A() {
    cmd = new CommandCodes();
  }

  .... code

  switch(int) {
    case cmd.typeID:  ... code;
  }


--- file
public final class CommandCodes {
  public final static int typeID = 1;
}


Seems this is as constant as it gets.  What's with the new release 1.3?
Avatar of Nushi
Nushi

in the switch 'case' has to get value during compilation
thats why you get this error.

place in your code some final variables for the number you know you can get if there are only few of them.

and this will solve the problem
Avatar of hank1

ASKER

so why not

public final cmd = new CommandCodes();
Your code should be

 switch(CommandCodes.int) {
   case cmd.typeID:  ... code;
 }

'int' is not a final in the scope of just the class A since int is defined to be a constant in its inner class.

>.  See the bug report on sunsite.  So if this is correct, >how does one create a shorthand reference to a long class >name?

I dont quite get what you are referring to.
Padma.
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hank1

ASKER

Thanks for such a detail.  Interesting that you mention interface... it died on me too in 1.3.