很多开源代码中(eg:storm)都会出现这样的代码
eg:
(^voiduploadChunk [this^String location ^ByteBufferchunk]
(
let
[
uploaders
(
:uploaders
nimbus
)
^
WritableByteChannel
channel
(
.get
uploaders
location
)]
(
when-not
channel
(
throw
(
RuntimeException.
"File for that location does not exist (or timed out)"
)))
(
.write
channel
chunk
)
(
.put
uploaders
location
channel
)
))
里面的^符号除了让代码的可读性更高还有什么用处呢?
看api介绍Clojure supports the use of type hints to assist the compiler in avoiding reflection in performance-critical areas of code
原来类型暗示还可以避免反射,提高效率。
原来类型暗示还可以避免反射,提高效率。