Skip to content

Instantly share code, notes, and snippets.

@timmc
Created March 6, 2013 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/5100962 to your computer and use it in GitHub Desktop.
Save timmc/5100962 to your computer and use it in GitHub Desktop.
Compiling Java against a class with abstract methods
;; Spit reified class to disk
(alter-var-root #'*compile-files* (constantly true))
;;=> true
;; Create an abstract-ish class
(class (reify java.util.List (size [this] 10)))
;;=> clj.core$eval1062$reify__1063
;; Nope, it's not an "abstract class"
(java.lang.reflect.Modifier/isAbstract (.getModifiers clj.core$eval1062$reify__1063))
;;=> false
*compile-path*
;;=> "/home/timmc/tmp/clj/target/classes"
// In /home/timmc/tmp/clj/
public class Test {
public static void main(String[] args) {
System.out.println(new clj.core$eval1062$reify__1063().size());
}
}
# In /home/timmc/tmp/clj/
javac -cp target/classes/ Test.java
mv Test.class target/classes/
java -cp target/classes/:/home/timmc/.m2/repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar Test
#=> 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment