-
-
Save Sophia-Gold/6e0abe5080b4db078220031ff3c95d6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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