Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created July 23, 2013 00:06
Show Gist options
  • Save gfredericks/6058783 to your computer and use it in GitHub Desktop.
Save gfredericks/6058783 to your computer and use it in GitHub Desktop.
Reflection with Executor?
(import '[java.util.concurrent Executors Executor])
(set! *warn-on-reflection* true)
(def ^Executor tp (Executors/newFixedThreadPool 4))
;; Reflection warning, NO_SOURCE_PATH:1:1 - call to submit can't be resolved.
(.submit ^Executor tp ^Callable (constantly 42))
@gfredericks
Copy link
Author

Note that in this particular case this leads not just to reflection but to incorrectness at runtime, as a Fn satisfies both the Runnable and the Callable case and so the wrong method can easily be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment