Since Clojure ends up running on a Java virtual environment, it is no surprise that we can create a Java object.
We can do this using the
new keyword, just as it is done in Java programming.
(def variablename(new Objectname))
Objectname: This is the major parameter for creating a Java object using Clojure.
variablename: This is used to hold the instance of the object on creation.
This keyword will create a new object, which will return a Java object.
(ns Project (:gen-class)) (defn func  (def obj(new Integer 1)) (println (+ 5 obj))) (func)
obj, and we assign it to
5to the newly created object, and we print it out using
View all Courses