This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-12
Channels
- # babashka (3)
- # beginners (9)
- # clojure (13)
- # clojure-dev (3)
- # clojure-europe (50)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (3)
- # clojurescript (3)
- # core-async (2)
- # dev-tooling (2)
- # honeysql (4)
- # hyperfiddle (2)
- # kaocha (1)
- # lsp (5)
- # off-topic (18)
- # polylith (4)
- # portal (2)
- # shadow-cljs (19)
- # squint (1)
- # vrac (1)
Suppose I have a function
(defn make-thing ^SomeObject [] ...)
then I use it like so
(let [thing (make-thing)]
;; assume someMethod exists on SomeObject instances
(.someMethod thing))
is thing
type-hinted with SomeObject
? I am writing code interfacing with Webauthn4J and the answer seems to be “no”. If the answer is “yes”, then am I hitting some strange bug with the Clojure compiler?I think that should work, but the way to check is to (set! *warn-on-reflection* true)
your example seems to not use reflection for me:
(defn make-thing ^String []
"")
(let [s (make-thing)]
(.length s))
I guess tehres something with the java library I am using then, because one of my function return type hints are being reported as unknown
cant provide a minimal repro yet since this is pretty complicated code and for now im ignoring the warning
does the method have other arguments? It can sometimes get a little hairy if a method has multiple overloads. In some cases, the compiler can't disambiguate and it will fall back to reflection.
also double check that you're hinting with the correct class/interface; I've wasted a lot of time after accidentally importing a similar class from a different package 😅
> one of my function return type hints are being reported as unknown
Reported by what?
Hello! When writing EDN in the particular case where the input is a data structure (and not e.g. just a string), why should I use pr-str
instead of str
? I.e. what does str in this case print that does not round-trip well? Tagged literals for sure. Anything else? Thank you! 🧵
Tagged lit. ex.:
(str (t/now))
=> "2024-01-12T09:53:33.027Z"
(pr-str (t/now))
=> "#clj-time/date-time \"2024-01-12T09:53:39.246Z\""
Anything that overrides .toString
.
(str (java.util.HashMap. {1 2 3 4}))
=> "{1=2, 3=4}"
(pr-str (java.util.HashMap. {1 2 3 4}))
=> "{1 2, 3 4}"
And even when there's no override and no custom tag, the results are different:
(pr-str (Object.))
=> "#object[java.lang.Object 0x6990cbde \"java.lang.Object@6990cbde\"]"
(str (Object.))
=> "java.lang.Object@7d05c924"
thank you!