Search code examples
javaapiintegershort

Why doesn't java.lang.Short have a reverse() method similar to java.lang.Integer


Why doesn't java.lang.Short (or Float or Double) class have a reverse method similar to java.lang.Integer ?

They both do have reverseBytes method though.

Why isn't the API list consistent ?

short can hold 2 bytes and it would have made sense to have a reverse method as well. Wouldn't it ?

Thanks


Solution

  • While I agree on the API criticism, it's pretty simple to emulate:

    short input = ...;
    short reversed = (short)(Integer.reverse(input) >> 16);
    

    So maybe the answer is:

    1. Not enough people felt it was necessary
    2. It's easy enough to simulate
    3. Someone wanted to show off with the implementation of Integer.reverse()
    4. Every line of code needs to maintained. Less code == less bugs, lower cost, easier maintenance.