I've been trying to find a way to collapse all these methods into one. Current I have these methodsdefault byte readByte(long address) {    return read(address, 1).get();}default int readShort(long address) {    return read(address, 2).getShort();}default int readInt(long address) {    return read(address, 4).getInt();}default long readLong(long address) {    return read(address, 8).getLong();}default float readFloat(long address) {    return read(address, 4).getFloat();}default double readDouble(long address) {    return read(address, 8).getDouble();}They are used to read a certain amount of bytes of a memory address (ex 8 bytes for long, 4 for int, 2 for short, etc).I find using the multiple methods is not very pleasing to look at. In theory I'd like a solution similar to something like this:default <T> T read(long address) {  if (T instanceof Long) {      return read(address, 8).getLong();  } else if (T instanceof Integer) {      return read(address, 4).getInt();  } else if (T instanceof Short) {      return read(address, 2).getShort();  } else if (T instanceof Byte) {      return read(address, 1).get();  } else if (T instanceof Double) {      return read(address, 8).getDouble();  } else if (T instanceof Float) {      return read(address, 4).getFloat();  } else if (T instanceof Boolean) {      return read(address, 1).get() == 1;  }  throw new RuntimeException(Unknown generic type!);}But I don't think that is possible due to the limitation of Java generics.Can you think of a better/less redundant solution?
Reading many kinds of numbers from a byte buffer
java;serialization