Fork me on GitHub

How do we interop following Java Class in Clojure?

GoogleIdTokenVerifier verifier =
    new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), new JacksonFactory());
I tried following which does not work.
(. GoogleIdTokenVerifier/Builder (NetHttpTransport.) (JacksonFactory.))
From the source code here I can see Builder is a class in that file. It looks like Builder is in the namespace GoogleIdTokenVerifier .


What's your import line like ?


maybe this will help maybe 20% down the page... hopefully someone more experienced with interop can chime in ^.^

dpsutton05:02:30 you can see how to access nested classes here. I would try (GoogleIdTokenVerifier$Builder. (NetHttpTransport.) (JacksonFactory.))


updated after reading it incorrectly


@U3ES97LAC The import statements are given below



@U11BV7MTK I have tried it before but unfortunately does not work It throws following error

Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: GoogleIdTokenVerifier$Builder


You need to import GoogleIdTokenVerifier$Builder


or use it fully-qualified


Thank you guys a lot.


Nested classes in Java aren't really "nested", they're more like "siblings".


Hmm got it.


I did came across the gist. But I reckon its better to use the SDKs instead of apis.


Hmm I think you are very close...


Hello again fellow beginners! Yesterday I started my journey into learning Clojure Spec, which is a really interesting tool for making assertions about data. I don't know so much about it yet, but I've gotten my feet wet with it. In my livestream today we're going to be continuing with the "name validator" coding challenge from Eric Normand's newsletter, which seems like a great use case for Spec and a good way to learn it: If you'd like to watch some guy with about four weeks of Clojure under his belt bungle his way through and learn a few things along the way, feel free to join! Coding challenge should start around 9:40-ish AM EST:


Maybe this is a stupid question, but I was wondering how much of the syntax in Clojure is set in stone.

(defn testfunc1 [a b] (+ a b))
(defn testfunc2 (vec a b) (+ a b))
The second one does not work, I thought the [a b] is just another way to say (vec ab). Is this because def is a special form?


defn is a macro and expects certain literal syntax


its looking for a vector which is how arguments are supplied. macros takes forms and return forms. so there's a difference between the literal [a b] and a form that will evaluate to the same form (vec a b)


You can write a macro that would contain an expression like (vec a b) that takes some expression as input, and constructs and returns an expression that looks like your first expression, but it would operate upon the symbols and other syntactic elements of the input expression given to the macro, not the "run-time" values of a and b.


Hi there. I have a bit of a question regarding how to do things the "Clojure" way. So let's say I have a Java class Foo with a bunch of methods that return void like setBar or calculateBaz. Is there a way where I can do something like this:

(-> newFoo
and return newFoo by the end?


doto is your friend here


I thought doto would only be your friend if you have methods that return the object they mutate?


Oh, never mind me. Forgetting things.


From the clojuredoc

;; Note that even though println returns nil, doto still returns the HashMap object
(doto (java.util.HashMap.)
      (.put "a" 1)
      (.put "b" 2)

šŸ‘ 4

doto doesn't thread the object i don't believe


So yeah it is my new friend


Thanks a lot šŸ™‚


Also to add another question on top of that, I've seen a utility library floating around somewhere which allows me to -> but with certain position within each form. Can anyone remember what it is?


there's a library that provides lots of arrow or threading functions. you might be able to use as->. Or I find it often better to figure out why the "position" changes and build forms that acknowledge that. a let binding or perhaps (->> (-> x foo bar) ...) can solve the "mismatch" problem many times


as a correction, -> needs to be on the outside, all the other arrows work inside it by design


that's valid there. its threading that single form through the thread last versions. You are talking about a different kinda pattern


ahh - I see what you are doing OK


that said, (-> x foo bar (->> ...)) does the same thing, and is more flexible


I'd call it the "canonical" version


fair. when the thread last form does the majority of the work or is longer i prefer my version as its a bit more clear to me


it makes it feel more contained. but its just pure personal preference


Exactly what I need. Thanks again šŸ™


DAE use babashka? I know borkdude is in here. Iā€™m looking for some reason to use clojure more (get more practice day to day doing real things) and I am pretty good at python/bash one liners, so this might be it


@grazfather There's also a #babashka channel with 400+ people


Yep, I just joined šŸ™‚


after I wrote that I figured Iā€™d check šŸ˜›


Hi, iam trying to find date difference in days, currently using [java-time :as jt] namespace. I have something which yields me difference between two dates in months. (.toTotalMonths(jt/period ?start-date ?end-date)) I want to extend this further and see what is the difference in days between these two dates. Is there any toDays method which will yield difference in days ?


  (:import (java.time LocalDate)
           (java.time.temporal ChronoUnit)))

(let [d1 (LocalDate/parse "2016-04-02")
      d2 (LocalDate/parse "2016-05-25")]
  (-> (ChronoUnit/DAYS) (.between d1 d2)))
=> 53
I think this works to get total number of days. Or with ..
(let [d1 (LocalDate/parse "2016-04-02")
      d2 (LocalDate/parse "2016-05-25")]
  (.. ChronoUnit/DAYS (between d1 d2)))
=> 53

šŸ‘ 3

this worked, thank you !!!


You'll probably have to fix the ns form


Yeah, I just wanted to show where ChronoUnit was coming from

šŸ‘ 3

(a lot of times it's not worth using a wrapper for Java Time stuff, although does make some type conversions easier)