sjac
sjac

Reputation: 2849

Generating Java Classes

I understand that one can use gen-class to generate a java class, however, I'm confused as to how I can generate a java class with constructors. Is it possible to generate a java class with a constructor, that does not extend or implement another class?

Upvotes: 3

Views: 127

Answers (1)

Alex Ott
Alex Ott

Reputation: 87329

I just generated following class with constructor:

(ns test.t1
  (:import (java.util HashMap))
  (:gen-class
   :main false
   :state state
   :init init
   :constructors {[java.util.HashMap] []}))
(defn -init [^HashMap tmapref]
  [[] tmapref])

and I able to create instance of it:

user> (test.t1. (java.util.HashMap.))
#<t1 test.t1@7d6ac92e>

Upvotes: 3

Related Questions