Skip to content
Advertisement

How do I pass a class to new indirectly in clojure

I have a clojure class (a namespace with a (:gen-class) clause). I then need to pass a constructed object to a java function. this works

JavaScript

However, if I need to refer to the class indirectly, that runs into some problems because new does not evaluate its argument. I am able to get the desired result by using

JavaScript

While this works it feels clunky. Is there a cleaner way or am I missing something ?

Advertisement

Answer

I would use the newInstance method to create a new instance from my-class that is of type java.lang.Class:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement