Is there any alternative way to implement a switch case in Java other than if else which is not looking good. A set of values will be there in combination, according to the selection corresponding method has to be executed.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Presumably you’re struggling with the requirement of case’s being constant. Typically this is a code-smell, but there are things you can do. You might want to raise and link to another question that details why you’re trying to switch.
In the example above, you might want to map to ‘handlers’, something like
which then makes this all turn into a lookup.
Again, it’s a bit of a smell, so please post a question which illustrates the reasoning.