I have a Java method with a switch statement.
It’s working fine, but I have a lot of cases, perhaps 20 or more, as shown below.
switch (result) // result is of type Enum
{
case 1:
break;
case 2:
break;
//----
//----
//----
default:
break;
} // End of Switch
Please let me know how to shift these cases into another file.
No, Java does not have an #include facility like C does.
You’re better off simply refactoring your logic. The fact that you’re asking at all tells me you may well need some better abstractions.
But, at a minimum you could do:
and then:
The Result holder is where you can get back any values you need.
But overall this is a patchwork, your design could probably use some work.