clojure-java-9
clojure-java-9 copied to clipboard
Calling static interface methods does not compile
Calls to static interface methods compile on Java 8 but not on Java 9 because of a new bytecode restrictrion.
public interface JDK8InterfaceMethods {
// cannot call either of these from Clojure
public static long staticMethod0(long v) { return v; }
public static String staticMethod1(String s) { return s; }
}
https://dev.clojure.org/jira/browse/CLJ-2284
Interface default methods are unaffected.
workaround macro
(defmacro interface-static-call
[sym & argtypes]
`(let [m# (.getMethod ~(symbol (namespace sym))
~(name sym)
(into-array Class ~argtypes))]
(fn [& args#]
(.invoke m# nil (to-array args#)))))
(def client
(interface-static-call S3Client/create))
(client)