Creating a Java List in Clojure for Java interop

I am losing the way I create a Java list in Clojure. I want to create a Java enumeration that uses the Java interface, and then pass it to a Java method, all in Clojure. I want to do this to work with the neo4j graph library (I don’t want to use some kind of pre-built interface, I want to write my own interaction code).

I searched on the Internet, and it looks like I can use the proxy method, but I can’t make it work for life. Here's the equivalent Java code I need to write to Clojure:

private static enum RelTypes implements RelationshipType { KNOWS } 

And here is my hit at him (this is not correct :():

 (proxy [org.neo4j.graphdb.RelationshipType] [] (KNOWS)) 

I am also wondering if there is a good website that documents such things that I am missing. I know about Clojure docs on the Clojure website, which is very useful, but, for example, I can’t always find what I need. Maybe I need a good reference?

+4
source share
1 answer

Why not just create an enum in Java? Sometimes giving up Java is the easiest answer.

Here's a very old thread about using proxies to define enumerations from Rich Hickey and Stuart Sierra along with some alternatives using gen-class . I think the proxy path should work with something like this for you:

 (proxy [Enum org.neo4j.graphdb.RelationshipType] [ "KNOWS" 1 ]) 

But this will not create anything that you would like to use for an external Java user, in which case the gen class is likely to be the best solution.

+8
source

All Articles