public
Created

Compiling Java against a class with abstract methods

  • Download Gist
1.repl.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
;; 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"
2.Test.java
Java
1 2 3 4 5 6
// In /home/timmc/tmp/clj/
public class Test {
public static void main(String[] args) {
System.out.println(new clj.core$eval1062$reify__1063().size());
}
}
3.bash
Shell
1 2 3 4 5 6 7
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.