Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling static interface methods does not compile #7

Open
ghadishayban opened this issue Feb 26, 2018 · 1 comment
Open

Calling static interface methods does not compile #7

ghadishayban opened this issue Feb 26, 2018 · 1 comment

Comments

@ghadishayban
Copy link

ghadishayban commented Feb 26, 2018

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.

@ghadishayban
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant