Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

string on a switch statement not working  RSS feed

 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Java are you using?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Henry Wong wrote:What version of Java are you using?


Build id: 20100617-1415
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's pretty old.  You should install the latest JDK from here.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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)
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!