Your first two statements are actually not equivalent. When you speak...
(def space? Character/isWhitespace)
... Clojure is trying to look for a static field (not a method) called isWhitespace
in java.lang.Character
. Of course, there is no such field, so you get a compilation error.
Other correct ways to rewrite the following statement ...
(defn space? [c] (Character/isWhitespace c))
... will be:
(def space? (fn [c] (Character/isWhitespace c)))
(defn space? [c] (. Character isWhitespace c))
Edit
Just to add, I believe that the reason Clojure allows (def wrap-space? space?)
that there is no ambiguity about what space?
. On the other hand, the Java static method may be overloaded with different sets of parameters or may share the same name with a static field. Therefore, for the Java static method alias, you need to clearly indicate which method / field you are using.
source share