Dollar sign ($) in symbol name clojure

I am writing a clojure parser and am in the following syntax:

(defn key
  "Returns the key of the map entry."
  {:added "1.0"
   :static true}
  [^java.util.Map$Entry e]
    (. e (getKey)))

      

What does "$" mean here? Is there any use for this kind of syntax outside of metadata?

+3


source to share


1 answer


This is the way to access nested classes in Clojure. In this case, you get access to which is the interface defined inside the interface Entry

Map

In Java you just write java.util.Map.Entry

, in Clojure you need to use the dollar sign:java.util.Map$Entry



From Clojure's Java Interop documentation :

"." a special form is the basis for accessing Java. It can be thought of as a member access operator and / or read as "in scope".

If the first operand is a character that resolves to the class name, access is considered a static member of the named class. Note that nested classes are named EnclosingClass$NestedClass

, in the JVM specification. Otherwise, it is assumed to be an instance member and the first argument is evaluated to create the target.

+5


source







All Articles