0

In the past I've been able to, e.g.

==> ((resolve (symbol "first")) [1 2 3])
1

but it doesn't seem to work in the same way for a Java static member. Like for instance I have an enum like this in its own file:

import org.neo4j.graphdb.RelationshipType;

public enum RelTypes implements RelationshipType {
  KNOWS
}

and in my Clojure code (using neo4j) I want to:

(defn relate-to
  [from to reltype-as-keyword]
  (.createRelationshipTo from to 
    (resolve (symbol (str "RelTypes/" (.toUpperCase (name reltype-as-keyword)))))))

but (resolve (symbol (str "RelTypes/" (.toUpperCase (name reltype-as-keyword))))) returns nil.

Update:

I see from another library that reify could be used (i.e., not using the enum defined elsewhere, instead creating RelationshipTypes on the fly).

e.g.

(reify RelationshipType
  (^String name [this] "KNOWS"))

But how do you do it by using the enum defined in the java file outside of the Clojure code?

tjb1982
  • 2,257
  • 2
  • 26
  • 39

1 Answers1

1

For this enum

package hello;

public enum MyEnum {

    ONE, TWO;

}

the following snippet of Clojure works:

(Enum/valueOf hello.MyEnum "ONE")