Search code examples
macrosclojure

Creating Objects in Clojure


There are two ways of instantiating objects in Clojure, with the new function or the . macro:

(new Object)
(Object.)

The majority of code I've seen uses the latter macro. I realise it's shorter, but the former seems much more readable to me. That's just a matter of preference, but is there a technical reason to use the latter macro?


Solution

  • No. They are exactly the same. The latter expands into the former at macro expansion time.