Dollar sign ($) in clojure symbol name
I've been writing a clojure parser and come across the follow syntax:
(defn key
"Returns the key of the map entry."
{:added "1.0"
:static true}
[^java.util.Map$Entry e]
(. e (getKey)))
What does that '$' mean here? Is there any usage for that kind of syntax outside of metadata?
This is the way to access nested classes in Clojure. In this case, you're accessing Entry
, which is an interface defined inside the Map
interface
In Java, you'd simply write java.util.Map.Entry
, in Clojure you need to use the dollar sign: java.util.Map$Entry
From the Clojure documentation on Java interoperability:
The '.' special form is the basis for access to Java. It can be considered a member-access operator, and/or read as 'in the scope of'.
If the first operand is a symbol that resolves to a class name, the access is considered to be to a static member of the named class. Note that nested classes are named EnclosingClass$NestedClass
, per the JVM spec. Otherwise it is presumed to be an instance member and the first argument is evaluated to produce the target object.
上一篇: 无法找到Clojure函数的来源
下一篇: 美元符号($)在clojure符号名称