5

When I try to close a socket through its Closeable interface, I get an exception:

new java.net.Socket().close();
// no error

((java.io.Closeable) new java.net.Socket()).close();
// Throws: java.lang.IncompatibleClassChangeError: interface not implemented

Why is that? The problem is only on Android devices, not on Java programs running on desktop.

csname1910
  • 1,195
  • 11
  • 14

1 Answers1

13

To quote Android issue tracker:

Socket implements Closeable only since API level 19 (kitkat) but that information isn't in the generated documentation.

Nigel Tufnel
  • 11,146
  • 4
  • 35
  • 31
  • This is a bad lack on the Android documentation... they should find a way to indicate that an interface is implemented (or a class is extended) only since a defined API level. However, thanks :) – Massimo Nov 06 '15 at 09:16