Search code examples
clojure

Why code with dot special form gives different results?


can you explain please? I don't understand, why the almost same code with dot special form and identity function has different results?

(. System getProperties) # => {"key" ...}
(. (clojure.core/identity System) getProperties) # => (err) No matching field found: getProperties for class java.lang.Class

I tried compare this:

(= (clojure.core/identity System) System) # true

and result is true


Solution

  • Static methods are special.

    In the first case, the compiler sees that System is a class and treats . as a static method call (source).

    In the second case, it treats . as a regular call on an instance of some class, and System is an instance of class Class, hence that error.