1

I've recently installed Java SE 7 on my Ubuntu and tried to compile code with switch on string but couldn't do that. I compiled from command-line. Why?

java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b146)
Java HotSpot(TM) Server VM (build 21.0-b16, mixed mode)

 incompatible types
 found   : java.lang.String
 required: int
        switch(attributes.getValue("tod")){
                                  ^
 1 error
Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
Oleksandr Bondarenko
  • 1,998
  • 1
  • 19
  • 22

2 Answers2

8

Verify your java compiler version:

javac -version
    ^
Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
0

its not problem of compiler but its problem of type casting and you are well know about typecasting,just check your program in eclipse and run program. check this method to get proper integer value in switch statement-attributes.getValue("tod"). User System.out.println(attributes.getValue("tod")); and you will get proper information of the passing value in switch.