问题描述
给定一个 java 包 x.y.z,我可以将 x.y.z 别名为更短的名称,以便我可以将包内的 java 类称为 my-alias.MyJavaClass.
Given a java package x.y.z, can I alias x.y.z to a shorter name, so that i can then refer to java classes inside the package as my-alias.MyJavaClass.
如果这不可能,我可以将所有类import
导入我的命名空间,但我不想手动指定每个类的名称,并且 clojure API 文档没有似乎很清楚是否可以自动import
一个包中的所有类.
If that isn't possible, I could just import
all classes into my namespace, but I don't want to specify the names of each class manually, and the clojure API docs doesn't seem clear on whether it's possible to import
all classes in a package automatically.
推荐答案
没有任何功能(目前).Java 包位于与 Clojure 不同的命名空间中,因此通常的别名技巧将不起作用.
There isn't any functionality for this (yet). Java packages are in a different namespace than Clojure's, so the usual alias tricks won't work.
你可以做的是导入每个类,这样你就可以避免使用完整的包+类名:
What you can do is import each class, which lets you avoid the full package+class name:
(import [java.io File Writer Reader])
(new File "/")
; #<File />
Rich 提供了他不支持 (import [java.io.*])
的理由 这里.
Rich provides his reasons for not supporting (import [java.io.*])
here.
这篇关于在 clojure 中别名 java 包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论