Add constructor to deftype created class

Viewed 2055

For the purposes of interoperability with Java, I need a class that has a nullary constructor that performs initialization. Objects of this class need to have something resembling mutable java fields (namely, the object represents the backend of a game, and needs to keep game state).

deftype does everything I want to do except provide a nullary constructor (since I'm creating a class with fields).

I don't need the fields to be publicly readable, so I can think of 4 solutions:

Use gen-class; I don't want to do this if I can avoid it.
Somehow encoding private member variables outside of the knowledge of deftype; I've been told this can't be done.
Writing a modified deftype that also creates a nullary constructor; frankly I don't know clojure well enough for this.
Taking the class created by deftype and somehow adding a new constructor to it.

At the end of this, I need to have a Java class, since I will be handing it off to Java code that will be making a new object from the class.

Are any of the solutions I suggested (or any that I haven't thought of) other than using gen-class viable?

2 Answers
Related