tags:

views:

156

answers:

2

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.

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.

A: 
import mypackage.*

Will import all classes in a package.

Mike Q
Sure - in Java. I'm using Clojure (http://clojure.org/).
npad
+5  A: 

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 provides his reasons for not supporting (import [java.io.*]) here.

Mike Douglas