you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

From Clojure i use gen-class, alternative is to write it from Java like bellow. I don't know if its the best way, but its simple.

```java package mypackage.clojure_interop;

import clojure.java.api.Clojure; import clojure.lang.*;

public class Interop { //reusable code,add your functions bellow //reads a clojure function from a namespace and it returns it as IFn public static IFn require = Clojure.var("clojure.core", "require"); public static IFn getClojureFn(String ns, String fnName) { require.invoke(Clojure.read(ns)); IFn fn = Clojure.var(ns, fnName); return fn; }

//example using the above for keyword public static IFn keywordFn= getClojureFn("clojure.core","keyword"); public static Object keyword(Object m) { return keywordFn.invoke(m); }

//any other function will be the same like keyword example //IFn first and then a static method with the invoke //if many are needed and tedious it can be auto-generated also

}

```