This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-22
Channels
- # announcements (2)
- # asami (123)
- # aws (17)
- # babashka (77)
- # babashka-sci-dev (23)
- # beginners (48)
- # biff (6)
- # calva (35)
- # cider (16)
- # clj-on-windows (1)
- # clj-yaml (19)
- # clojure (36)
- # clojure-europe (78)
- # clojure-nl (5)
- # clojure-norway (8)
- # clojure-poland (3)
- # clojure-uk (16)
- # clojurescript (17)
- # cursive (6)
- # datahike (3)
- # datalevin (26)
- # duct (7)
- # emacs (41)
- # events (2)
- # fulcro (7)
- # graphql (5)
- # honeysql (13)
- # juxt (3)
- # kaocha (7)
- # lsp (5)
- # malli (12)
- # off-topic (14)
- # pathom (3)
- # portal (1)
- # rdf (9)
- # reitit (3)
- # remote-jobs (2)
- # shadow-cljs (37)
- # spacemacs (5)
- # tools-build (1)
- # tools-deps (20)
- # xtdb (2)
Hi all, I'm having trouble understanding how to call Java instances methods from within Clojure. Since I have no previous Java experience I'm kind of mind boggled and the explanations I found are puzzling. I found this link (http://xahlee.info/clojure/clojure_calling_java.html) which explains how to use java methods with examples in Java code and Clojure code, e.g.: Java's object_name.method_name(args)
would become (. object_name method_name args)
or (.method_name object_name args)
.
So far so good and I can get these to work:
(.format
(java.text.SimpleDateFormat.
"MMMM"
(new java.util.Locale "nl", "NL"))
(.parse
(java.text.SimpleDateFormat.
"yyyy-MM-dd")
"2022-07-01")) ; => "juli"
-
(let [df (java.time.format.DateTimeFormatter/ofPattern "MMMM" (new java.util.Locale "nl", "NL"))
date (java.time.LocalDate/now)]
(.format df date)) ; => "september"
But I cannot for the life of me figure out how to call the instance method getLocale
from java.time.format/DateTimeFormatter
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#getLocale--
It says here that its public Locale getLocale()
where Locale
is a link that leads to java.util.Locale
but that class doesnt have getLocale... I'm confused(let [df (java.time.format.DateTimeFormatter/ofPattern "MMMM" (new java.util.Locale "nl", "NL"))]
(.getLocale df))