4 ms·
Yes. Very well. https://www.clojure.org/reference/java_interop https://www.clojure.org/reference/java_interop
by grzm 7y ago
Yes. Very well. https://www.clojure.org/reference/java_interop https://www.clojure.org/reference/java_interop
- The_rationalist 7y agoInterested but how much as good as with kotlin? Being compatible is one thing, being as idiomatic is another.
- grzm 7y agoDefine 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.
- dominotw 7y ago> being as idiomatic yea kotlin prbly is a better choice if you mainly want to use java's libraries and write idiomatic java. Clojure is not 'better java' like kotlin, its a completely different paradigm.
- Scarbutt 7y agoNowhere near as good or as seamless as Kotlin interop, Kotlin made interop a priority/first class feature. When using a Java library in Clojure, many times its just better to just write some Java for your Clojure program specifically for the purpose of calling it from Clojure.
- didibus 7y agoThat hasn't been my experience. I've always been able to make use of Java libraries directly from Clojure in a straightforward way. In fact, sometimes I joke it's easier to do Java in Clojure than in Java Can you describe the kind of situations that you faced issues in? P.S.: Also, Clojure has first class interop... It's a part of its fudamental design.
- Scarbutt 7y agoFrom Cursive's author https://old.reddit.com/r/Clojure/comments/5twabp/new_clojurians_ask_anything/ddq55z4/ https://old.reddit.com/r/Clojure/comments/5twabp/new_clojuri...
- trmsw 7y agoIn what sort of situations have you needed to write more Java to use a Java library from Clojure? I've never felt the need to do this. It's sometimes helpful to write a Clojure wrapper for a Java library on order to use it in a more Clojure-y way.
- Scarbutt 7y agoFrom Cursive's author https://old.reddit.com/r/Clojure/comments/5twabp/new_clojurians_ask_anything/ddq55z4/ https://old.reddit.com/r/Clojure/comments/5twabp/new_clojuri...
- mateuszf 7y ago> When using a Java library in Clojure, many times its just better to just write some Java for your Clojure program specifically for the purpose of calling it from Clojure. What? Calling Java from Clojure couldn't be any easier. The same as calling JavasScript from ClojureScript
- Scarbutt 7y agoFrom Cursive's author https://old.reddit.com/r/Clojure/comments/5twabp/new_clojurians_ask_anything/ddq55z4/ https://old.reddit.com/r/Clojure/comments/5twabp/new_clojuri...
- didibus 7y agoNot sure what you mean. It is idiomatic to not rebuild things Java offers in Clojure and to instead just use interop with Java. Using Java from Clojure I'd say is as good as Kotlin. Using Clojure from Java isn't as good as Kotlin, but it is still pretty good. Only certain things get messy, like in frameworks where you need to extend a class and override methods to set some behavior. Or frameworks that make heavy use of annotations. Since Clojure isn't OO, doing those are a bit trickier.