Skip to content

Instantly share code, notes, and snippets.

@adambard
Created March 27, 2012 17:23
Show Gist options
  • Save adambard/2218162 to your computer and use it in GitHub Desktop.
Save adambard/2218162 to your computer and use it in GitHub Desktop.
Using Java from Clojure in plain !@#%^%ing language, with some simple goddamn examples.
; Short answer: use import to import a given class
; In java:
; import java.io.File;
(import java.io.File)
; Preferred: put it in your ns
(ns my-namespace
(:import java.io.File))
; Instantiate an object with an argument
;
; File f = new File("C:/file.txt");
;
(File. "C:/file.txt")
; Use some methods
;
; File f = new File("C:/file.txt");
; if(f.exists()){
; return f.getName();
; }else{
; return null;
; }
;
(let [f (File. "C:/file.txt")]
(if (.exists f)
(.getName f)
nil))
; Use a static method, with arguments
;
; File.createTempFile("prefix", "suffix", "C:\Temp");
;
(File/createTempFile "prefix" "suffix" "C:\Temp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment