A quick hack in Java, it comes handy when supporting old Java code (pre Java 5, where Closeable is missing): public static void universalClose(Object o) { try { o.getClass().getMethod("close", null).invoke(o, null); } catch (Exception e) { throw new IllegalArgumentException("no close() method"); } } testcase: public static void main(String[] args) { Socket socket = new Socket(); universalClose(socket); } |

