You can add type hints to the argument vector(s) of
defn to declare the return type of a function like so (with warn-on-reflection being true):
user> (defn foo ^String [s] s)
user> (.substring (foo "hallo") 1 2)
But sadly, the same doesn't work with
user> (.substring ((fn ^String [s] s) "hallo") 1 2)
Reflection warning, NO_SOURCE_PATH:1:1 - call to substring can't be resolved.
user> (letfn [(foo ^String [s] s)]
(.substring (foo "hallo") 1 2))
Reflection warning, NO_SOURCE_PATH:2:7 - call to substring can't be resolved.
I don't see why this feature is available to
defn but not to
letfn. I even consider it a kind of defect, because anything else including :pre/:post are also supported by the latter two, so the support for hinting the return type should be there simply because of analogy.