Have seen this comment in a method:
//I wonder why Sun made input and output streams implement Closeable and left Socket behind
It would prevent creation of wrapper anonymous inner class which implements Closeable which delegates its close method to an instance of Socket.
Closeable was introduced in Java5 whereas Socket was introduced in JDK 1.0. In Java7 Socket will be Closeable.
EDIT
You can use reflection in order to close any "closeable" object in Java 4/5/6 simply by testing the presence of a close method. Using this technique allow you to close, say, a ResultSet (that has a close() method but doesn't implements Closeable):
public static universalClose(Object o) {
try {
o.getClass().getMethod("close", null).invoke(o, null);
} catch (Exception e) {
throw new IllegalArgumentException("missing close() method");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With