Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
A Thorny Issue In Clojure Java Interop
(ns a-thorny-issue.core
(require [clojure [reflect :as r] [pprint :as pp]]
[ [javadoc :as jd]])
(import [java.util.concurrent Executors Future ExecutorService]))
(comment (pp/print-table [:name :parameter-types :return-type]
(sort-by :name (:members
(r/reflect java.util.concurrent.ExecutorService))))
(jd/javadoc java.util.concurrent.ExecutorService))
(def an-executor (Executors/newSingleThreadExecutor))
(defn submit-callable [c ex]
(.submit ex c))
(defn some-hard-work []
(instance? Callable some-hard-work)
(instance? Runnable some-hard-work)
(instance? Future (submit-callable some-hard-work an-executor))
(.get (submit-callable some-hard-work an-executor))
(defn submit-callable-reify [c ex]
(.submit ex (reify Callable (call [_] (c)))))
(instance? Future (submit-callable-reify some-hard-work an-executor))
(.get (submit-callable-reify some-hard-work an-executor))
(defn submit-callable-hint [^Callable c ex]
(.submit ex c))
(defn submit-callable-hint2 [c ex]
(.submit ex ^Callable c))
(defn submit-callable-cast [c ex]
(.submit ex (cast Callable c)))
(defn submit-callable-hint3 [c ex]
(let [^Callable the-fn c]
(.submit ex the-fn)))
(defn submit-callable-hint4 [c]
(let [ex (Executors/newSingleThreadExecutor)
^Callable the-fn c]
(.submit ex the-fn)))
(defn submit-callable-hint5 [c ex]
(let [the-ex ex
^Callable the-fn c]
(.submit ex the-fn)))
;; Success!!
(defn submit-callable-hint6 [^Callable c ^ExecutorService ex]
(.submit ex c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.