Using 3rd party java libraries, like com.jcraft.jsch, with clojure

一世执手 提交于 2019-12-04 04:26:18

For java classes use import:

(import java.util.ArrayList)

;// or use a prefix for multiple classes:
(import [java.util ArrayList Collection])

;// or preferably in the ns declaration:
(ns my.lib
  [:import [java.util ArrayList Collection]])

user=> (def al (ArrayList.))
#'user/al
user=> (.add al "hi")
true
user=> (.size al)
1

Note the package and class names do not need to be quoted since import is a macro.

Also there is no equivalent to import java.util.*; You need to specify which classes you want to import.

Try using import for non-clojure stuff.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!