• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Can switch() be given more capability ?

 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can only handle ints, chars...and enums. Why cant they make it take strings as well ?

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java 7 has an update for that- Project Coin

[Edit: Added the Links]
 
author
Posts: 23931
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

Rahul Sudip Bose wrote:It can only handle ints, chars...and enums. Why cant they make it take strings as well ?



I believe this is an enhancement for Java 7.

[EDIT: beaten to the answer again]

Henry
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just started making my own class PowerSwitch{} for fun- please tell me if i am thinking in the right direction. (its just in the planning phase)
this will take strings, convert them to lowercase and use them as keys in a map. these keys will be mapped to int objects which will be used in the switch of this class.

Any suggestions , ideas etc welcome.

PS : i was wondering if i should leave this since others are already doing it and...well there is scjp
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Rahul Sudip Bose wrote:
[EDIT: beaten to the answer again]



i am not so sure what this means.

 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always map the int with some string values, use the int for switch and then retrieve the string based on the int value.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul Sudip Bose wrote:

Henry Wong wrote:
[EDIT: beaten to the answer again]



i am not so sure what this means.



that means- there a difference of less than a minute between my and Henry's answer.
 
Marshal
Posts: 77285
371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rahul Sudip Bose wrote:It can only handle ints, chars...and enums. Why cant they make it take strings as well ?

. . . or anything which can be implicitly cast to an int, ie shorts and bytes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic