Created
March 27, 2012 17:23
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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