Recently I saw a lot of similiar code chunks in one project, which were written the following way:
String usedAlphabet = "x3w4tnu34urgbgierg";
byte c = // (something initialized earlier)
return usedAlphabet[(int)(c / 16)];
Now, what might be the reason to use the (int) cast while accessing the corresponding array?
To me, it seems redundant, but I might be wrong or I may lack knowledge about the type casting mechanics.
As you already found out, the cast is redundant. Does it aid in readability? Maybe, depending on the context. What could be done to really aid the readability of this “unobvious array indexing”? Good names I tell you (of course, the author should find the right names that communicate his intent, I’ve just made them up here):