May 2018
Beginner to intermediate
290 pages
6h 43m
English
So far we’ve been using the fully qualified classnames for files: java.io.File and java.awt.Rectangle. Since that can be a bit of a mouthful, Clojure provides import. In much the same way that you can use require/:as to create syntactical shortcuts for the denizens of your Clojure namespaces, you can use import to do the same with Java classes. In the REPL you can use the stand-alone form of import:
| | ;; In the REPL. |
| | |
| | (import java.io.File) |
If you are writing a .clj file you should include the import in the ns at the top:
| | (ns read-authors |
| | (:import java.io.File)) |
Note that there is no quoting needed in either form. However you do it, once you have imported a class you can refer to the class without its package name:
| | (def authors ... |
Read now
Unlock full access