Skip to content

Instantly share code, notes, and snippets.

@Sophia-Gold
Last active September 19, 2017 19:19
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 Sophia-Gold/6e0abe5080b4db078220031ff3c95d6d to your computer and use it in GitHub Desktop.
Save Sophia-Gold/6e0abe5080b4db078220031ff3c95d6d to your computer and use it in GitHub Desktop.
(ns bitwise.reflection-test)
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(defn foo1 [^String string]
(reduce + 0
(map (comp long char) string)))
(defn bar1 [^String string]
(inc (foo1 string)))
(defn foo2 ^long [^String string] ;; type hint for return value
(reduce + 0
(map (comp long char) string)))
(defn bar2 [^String string]
(inc (foo2 string)))
;; => (bar1 "baz")
;; => Boxed math warning, bitwise/reflection_test.clj:10:3 - call: public static java.lang.Number clojure.lang.Numbers.unchecked_inc(java.lang.Object).
;; => (bar2 "baz")
;; all good :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment