I saw a Clojure function like
(defn strFun
[#^String str]
(...))
I guess the #^String is type hint but what is the #and ^ before the String?
It's the old format for specifying simple metadata tags before it was just ^TagName. You will see it in code written during this transition from time to time, though there is no need to use it.
user> #^String ["hello"]
["hello"]
user> (meta #^String ["hello"])
{:tag java.lang.String}
is the same as not using the #
user> (meta ^String ["hello"])
{:tag java.lang.String}
user>
PS: in this example I tagged a vector with the tag java.lang.String. This point to note is that the symbol you use as a tag will be resolved and the value that symbol resolves to will be used as the tag. So you can't use an undefined symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With