3 ms·
Array as replacement for switch? Maybe for simple cases
by high_na_euv 2y ago
Array as replacement for switch? Maybe for simple cases
- SillyUsername 2y agoNot as a general case, but something like (not withstanding missing range checks) below: private String[] alphabetIndex = new String["A", "B"...]; public String getLetterAtIndex(int index1Based) { return alphabetIndex[index1Based-1]; }
- high_na_euv 2y agoSwitch is useful for simple code dependent on e.g kind or expression, not just as a mapper