问题
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.
回答1:
To quote Android issue tracker:
Socket implements Closeable only since API level 19 (kitkat) but that information isn't in the generated documentation.
来源:https://stackoverflow.com/questions/21353474/android-exception-using-closeable-interface-with-socket