Java 如何使用clojure实例化路径对象

Java 如何使用clojure实例化路径对象,java,clojure,java.nio.file,Java,Clojure,Java.nio.file,由于Path类没有公共构造函数,因此使用Path对象中的getfactory方法创建Path对象 e、 g 我们如何以clojure的方式做到这一点?user>(java.nio.file.path/get/home/justin)(放入数组[“.lein”“profiles.clj]”) user> (java.nio.file.Paths/get "/home/justin" (into-array [".lein" "profiles.clj"])) #<UnixPath /h

由于
Path
类没有公共构造函数,因此使用
Path
对象中的
get
factory方法创建Path对象

e、 g

我们如何以clojure的方式做到这一点?

user>(java.nio.file.path/get/home/justin)(放入数组[“.lein”“profiles.clj]”)
user> (java.nio.file.Paths/get "/home/justin" (into-array [".lein" "profiles.clj"]))
#<UnixPath /home/justin/.lein/profiles.clj>
#
varargs java方法需要一个包含所有剩余arg的数组作为其最终参数

为了使方法分派与正确的方法匹配,需要数组外的第一个字符串

为了完整起见,下面是一个使用URI的示例(更简单):

user>(java.nio.file.path/get(java.net.URI)。”file:///home/justin"))
#

(路径/get/home/admin“Migrations”“/blog/tables/6-rating.xml”)编译器异常java.lang.IllegalArgumentException:无匹配方法:get,编译:(无源路径:5:2)
(路径/get/home/debianout/Migrations/blog.sakhunzai/tables/6-rating.xml”)ClassCastException java.lang.String不能强制转换为java.net.URI用户/eval5598(无源文件:11)
“多个参数必须在一个数组中传递仍然是事实,但varargs功能会自动并隐藏该过程。”clojure不编译为java,它只是缺少java编译器提供的功能。
user> (java.nio.file.Paths/get "/home/justin" (into-array [".lein" "profiles.clj"]))
#<UnixPath /home/justin/.lein/profiles.clj>
user> (java.nio.file.Paths/get (java.net.URI. "file:///home/justin"))
#<UnixPath /home/justin>