Once again, nice tutorial. The only thing to add here: besides the (new String "abc"), you can also use (String. "abc"). I believe that the latter special form is actually more idiomatic. At least I'm seeing it much more often than (new) call. One of the very useful macros is also (doto). It allows "chained" execution of side-effectful (all those setters, .put .add etc) methods on some object. Very handy for working with java APIs which don't offer "fluent" (builder-based) API. For example, where in java you would have to define a variable and use it over and over again to call functions... Map myMap = new HashMap(); myMap.put("some", "value"); myMap.put("another", "value"); In clojure, you can simply do (doto (java.util.HashMap.) (.put "some" "value") (.put "another" "value")) "fluent API" for free. Beauty and simplicity of macros. Btw it gets expanded to (let* [G__7500 (java.util.HashMap.)] (.put G__7500 "some" "value") (.put G__7500 "another" "value") G__7500)
Yeah you could do that if you want to copy and paste a premade class in :) you could also rewrite it with Clojure and use interop. Depends on the project!
This was really useful thank you very much. If can suggest and extension or a part 2 to this video. It would be great to have a video on how to read javadocs for non-java people :)
@@onthecodeagain I don't mean how to make the docs but more on how to make sense if Java docs for people like myself that have just started doing clojure but have zero experience with the jvm and jvm docs which you usually have to read and refer to when doing interop
Once again, nice tutorial.
The only thing to add here: besides the (new String "abc"), you can also use (String. "abc"). I believe that the latter special form is actually more idiomatic. At least I'm seeing it much more often than (new) call.
One of the very useful macros is also (doto). It allows "chained" execution of side-effectful (all those setters, .put .add etc) methods on some object. Very handy for working with java APIs which don't offer "fluent" (builder-based) API.
For example, where in java you would have to define a variable and use it over and over again to call functions...
Map myMap = new HashMap();
myMap.put("some", "value");
myMap.put("another", "value");
In clojure, you can simply do
(doto (java.util.HashMap.)
(.put "some" "value")
(.put "another" "value"))
"fluent API" for free. Beauty and simplicity of macros.
Btw it gets expanded to
(let* [G__7500 (java.util.HashMap.)]
(.put G__7500 "some" "value")
(.put G__7500 "another" "value")
G__7500)
This is awesome advice thanks man!
Awesome video, wasnt aware that it was this easy to have code interoperability between the two!
Thanks!
Learning something new every time. Great stuff! I love the format!
Thanks man!
great job dude,
Keep make more educative videos.
Thanks
-Clojurian from Indonesia
Super awesome. Your videos are easy to follow. Thanks for sharing this great tutorial.
Glad you liked it :)
Thanks so much for making this!! I'd defo pay for your patreon
Very informative videos Dan. Thanks a mil bud!!
Oh cool man!! So if your doing a Clojure project and find a class would make sense, you build a Java class then import it? Is that the normal pattern?
Yeah you could do that if you want to copy and paste a premade class in :) you could also rewrite it with Clojure and use interop. Depends on the project!
Next video - using Clojure from Java. Video preview should show a coffey cup with Clojure logo Latte art.
Dude after I made this video I couldnt believe I didnt show that :/
@@onthecodeagain You have to sip Clojure out of the java cup to make the meme complete.
@@onthecodeagain You can make a whole video about **ns** macro. It can construct methods and stuff. Basically a class constructor for java interop.
@@onthecodeagain hahah i would like to see that too
This was really useful thank you very much. If can suggest and extension or a part 2 to this video. It would be great to have a video on how to read javadocs for non-java people :)
Thanks man! Ill probably do a video showing how to make the docs at some point :)
@@onthecodeagain I don't mean how to make the docs but more on how to make sense if Java docs for people like myself that have just started doing clojure but have zero experience with the jvm and jvm docs which you usually have to read and refer to when doing interop
@@GOZES oh ok I get you!
Good stuff! Keep it up!
banging intro
This bad example not work
I tried and it works. You have to be patience. For some reason working Clojure is quite tricky sometimes.
Create a ticket