Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using switch case?

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

compile time error???
answer is
constant expressions needed???x and y are not constants...
what does this mean??
 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is with variable y: it should be a constant (that is should be marked final) and it should be a compile time constant which means that y should be declared and initialized at the same time.Refer to page 336 Chapter 5 of K & B .

so the correct code is :

 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maggie you are not following the quoting of source rule properly. You've asked a lot of questions without a proper source (like this, this, this and this). Quoting source is not optional at javaranch. If you don't quote the source properly, then we might have to delete your questions...
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..i will do that from next post..actually i am trying lots of code on my own too.so its a combination of all that..anyways i will take care from next time....
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maggie joseph wrote:ok..i will do that from next post..

No. Tell us what the source of the above question is now. As you've been told multiple times, it's required on JavaRanch.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The case constant must be a compile time constant! Since the case argument has to be resolved at compile time, that means you can use only a constant or final variable that is assigned to literal value.

I think, this may help to you.!
 
Alpesh Rathod
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:The case constant must be a compile time constant! Since the case argument has to be resolved at compile time, that means you can use only a constant or final variable that is assigned to literal value.

I think, this may help to you.!



Very good very good...
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question is from Examlab most probably.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic