In fact, I suspect that you might make a performance hit. There are only Java byte codes for bitwise operations on int and long values. Therefore, short values in the permission and requested variables need (theoretically) extension of the character before the operation is performed.
(And besides, I think you will find that native bit instructions are only available in 32 and 64 bits. Or, if there are 8 or 16 bit versions, they will take as many hours as the 32 bit version. CPU datapaths will have at least 32 bits wide, and for and / or / xor it is impossible to speed up the work of narrower types.)
In addition, although the three variables are of type short , the JVM will allocate the same number of bytes to store them. This is a consequence of how the JVM is designed.
So, if your goal of using short was to save space or time, this probably won't help. But the only way to make sure you use the profiler to compare the short and int versions of your application ... or better yet, just forget about it.
source share