You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Buffers.java 877B

1234567891011121314151617181920
  1. import java.nio.Buffer;
  2. import java.nio.ByteBuffer;
  3. public class Buffers {
  4. /**
  5. * Running this method will fail during runtime on JDK 8, if compiled on JDK 9+ with {@code -source 8 -target 8},
  6. * because the API has changed: In JDK 8 there was only {@code Buffer.flip()}, but since JDK 9 it is overloaded by
  7. * {@code ByteBuffer.flip()}.
  8. * <p>
  9. * Therefore, it is imperative to compile against the old API, using the correct boot classpath. On JDK 9+, the
  10. * canonical way to do this is to use {@code --release 8}, because the JDK contains a compatibility layer exactly for
  11. * this purpose.
  12. * <p>
  13. * If incorrectly compiled against JDK 9+ API, this will fail with:
  14. * <pre>{@code java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer; }</pre>
  15. */
  16. public static Buffer flip(ByteBuffer buffer) {
  17. return buffer.flip();
  18. }
  19. }