Rob Lachlan
Rob Lachlan

Reputation: 14479

Is it possible to create a clojure type with a main method? (Using deftype, not gen-class)

The examples I've seen of main methods defined in clojure all use gen-class, together with (defn -main ...). Is it possible to define a class with an executable main method using deftype?

Upvotes: 3

Views: 419

Answers (2)

mikera
mikera

Reputation: 106401

A main method only makes sense if you AOT compile it (with gen-class or similar).

If you tried to define it in any other way, then it wouldn't be possible to use it since you would need to launch the clojure compiler / environment first. So you'd have to start the app by calling some other main() method instead.....

Upvotes: -1

aav
aav

Reputation: 2489

it is not possible, because interfaces (protocols) that deftype can implement cannot have static methods.

Upvotes: 8

Related Questions