Typed Clojure: Features, Formal Model, and Java Interoperability
1. Typed Clojure Core Features
1.1 Java Interoperability and Type Errors
Typed Clojure can integrate with the Clojure compiler to avoid expensive reflective calls. For example:
(.getParent (new File "a/b"))
;=> "a" :- (U nil Str)
However, if a specific overload cannot be found based on the surrounding static context, a type error is thrown.
(fn [f] (.getParent f)) ; Type Error: Unresolved interop: getParent
Function arguments default to Any , but ascribing a parameter type allows Typed Clojure to find a specific method.
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



