Android: Exception using Closeable interface with Socket

为君一笑 提交于 2019-12-30 23:52:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!