I never saw that code “case” in the “switch” was framed by curly braces – {}. Can I use braces to hide variables in case? Or is it a bad practice? What are the possible consequences?
I need to use the switch, in which each case is formed from the same type of variables (which in my opinion is better to keep the same name) but which have different values.
Dialog dialog;
switch (id) {
case ID_1: {
String[] keys = ...; // some array
String[] values = ...;
...
return dialog;
}
...
case ID_2: {
String[] keys = ...; // different values
...
return dialog;
}
default:
return null;
}
}
Yes you can.
It is possibly a sign that you could refactor your code – but hard to tell without seeing what the code does in each
case.None apart from limiting the scope of those variables, which is your goal.