我正在阅读Programming Clojure,并在src / examples / gulp.clj中遇到了以下代码。我无法理解StringBuilder,FileInputStream等之后的点是什么意思 -
(ns examples.gulp
(:import (java.io FileInputStream InputStreamReader BufferedReader)))
(defn gulp [src]
(let [sb (StringBuilder.)]
(with-open [reader (-> src
FileInputStream.
InputStreamReader.
BufferedReader.)]
(loop [c (.read reader)]
(if (neg? c)
(str sb)
(do
(.append sb (char c))
(recur (.read reader))))))))
任何人都可以说清楚。
答案 0 :(得分:13)
类名后面的点只是调用类的构造函数的特殊语法。
(macroexpand '(StringBuilder. "foo"))
;=> (new StringBuilder "foo")