Covariant return types for some methods in the
java.nio.Buffer were
introduced in JDK 9.
If calls to these methods are compiled with javac from JDK 9+ using
-target 8 -source 8
then the call sites will invoke the covariant methods in the subclass. For example:
static void reset(ByteBuffer buf) {
buf.reset();
}
will result in:
0: aload_0
1: invokevirtual #7 // Method java/nio/ByteBuffer.reset:()Ljava/nio/ByteBuffer;
4: pop
5: return
This will result in a
NoSuchMethodError when run on JDK 8. The workaround for this is to
coerce the receiver for calls to the covariant methods to
Buffer.