3 ms·
Define idiomatic. As an example, I find myself using the java.time package quite frequently. An example: (ns dev.scratch.time-ex (:import (ja
by grzm 7y ago
Define idiomatic. As an example, I find myself using the java.time package quite frequently. An example:
(ns dev.scratch.time-ex
(:import
(java.time Duration)
(java.util Date)))
(let [from (Date.)
until (-> from (.toInstant) (.plus (Duration/ofHours 12)) (Date/from))]
[from until])
Returns a 2-element vector containing two java.util.Date objects, the second twelve hours in the future of the first. Here I'm using Date, Instant, and Duration classes. It's consistent with Clojure syntax (methods being first items in a list), and remembering to use . or / (roughly for instance or static methods) for calling Java methods. Using something like the thread-first macro (->) is idiomatic Clojure, and it's not my goal to convince you that Clojure syntax and style is better, just that Java is immediately and idiomatically available (from a Clojure point of view).
I find very little friction in using Java directly from Clojure code. I can't speak to comparisons with Kotlin as I have no experience using it.