• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string on a switch statement not working

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have Month; written in the switch statement above but i'm getting a error saying "Cannot switch on a value of type String. Only convertible int values or enum constants are permitted".
what does this mean? can anyone help?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What version of Java are you using?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you installed Java 8?  What is printed when you type this on the command line?

java -version
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:What version of Java are you using?



Build id: 20100617-1415
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's pretty old.  You should install the latest JDK from here.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

orry kaplan wrote:

Henry Wong wrote:What version of Java are you using?



Build id: 20100617-1415



That's not we are after, that looks like the IDE build number.

Do it at command prompt. Output looks like

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use
if (somethingBoolean) return true; else return false;
or similar. Use
return somethingBoolean;
Reference: very old style guide.
Don't use
== true
which is not only poor style, but also error‑prone. Every now and again we see somebody write = by mistake.
Not if (somethingBoolean == true) ... but if (somethingBoolean) ...
The same applies to == false
Not if (somethingBoolean == false) ... but if (!somethingBoolean) ...

You will often find your Boolean expressions easier to read if you can name them so you use the true version without the bang sign !
You appear to have two blocks of code both working out whether you have a leap year. Don't repeat code like that. You sh‍ould reuse the method written earlier.
 
reply
    Bookmark Topic Watch Topic
  • New Topic