java.lang.IllegalArgumentException:无法解析类名:FileReader
我们正在尝试编写一些Clojure代码,几分钟前我们成功地编译了它,但现在我们得到了这个随机异常java.lang.IllegalArgumentException:无法解析类名:FileReader,exception,macros,clojure,illegalargumentexception,Exception,Macros,Clojure,Illegalargumentexception,我们正在尝试编写一些Clojure代码,几分钟前我们成功地编译了它,但现在我们得到了这个随机异常 CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: FileReader, compiling:(myproject\core.clj:24:17) 这是我们的代码: (ns myproject.core) (defmacro safe ([bindings & code]
CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: FileReader, compiling:(myproject\core.clj:24:17)
这是我们的代码:
(ns myproject.core)
(defmacro safe ([bindings & code] form)
(if (list? bindings)
`(try
~bindings
(catch Throwable except# except#))
(if (= (count bindings) 0)
`(try ~code
(catch Throwable except# except#))
`(let ~(subvec bindings 0 2)
(try
(safe ~(subvec bindings 2) ~@code)
(catch Throwable except# except#)
(finally
(. ~(bindings 0) close))))))) ;;safe
(def div(safe (/ 12 2)))
(def v (safe [s (FileReader. (java.io.File. "M:/test.txt"))] (. s read)))
我们发现了问题
我们必须从java导入FileReader
(import '(java.io FileReader File))
或者,您可以在不导入的情况下使用限定名称,就像您在
java.io.File
中所做的那样。