Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of Wrappers in switch() and case x: statements

 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above program,
when i used Integer x1 inside switch() as, switch(x1) ,it works.
But when i use x2 in a case statement as, case x2 : s += "c" , does not compile. WHY???
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because the value after case needs to be a compile time constant and x2 is not because wrapping happens at runtime. If you change it to a int it works just fine.
 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation, Wouter.
 
Jeevan Reddy
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter Oet wrote:That is because the value after case needs to be a compile time constant and x2 is not because wrapping happens at runtime. If you change it to a int it works just fine.

Thanks Wouter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic