如何在 Clojure 中对字符串向量进行类型提示?
我的函数返回一个序列,例如字符串向量。
这是一个微不足道的示例(实际上,它是从类型推理中得出的,但说明了这一点):
(defn ^PersistentVector myfunction [a b]
;; do something with strings
)
(my-function ["A" "B"])
我该如何键入此提示以表明这些是专门的字符串?
类似^persistentVector< string>
?
My function returns a sequence, for example Vector of Strings.
Here is a trivial example (which in practice would be derived from type inference, but which illustrates the point):
(defn ^PersistentVector myfunction [a b]
;; do something with strings
)
(my-function ["A" "B"])
How do I type-hint this to show that these are specifically Strings?
Something like ^PersistentVector<String>
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PersistentVector
可以包含任何类型的对象,无法强制执行内容的类型,因此不存在此类类型提示的表示法。您可以让它返回一个 Java 字符串数组,然后您可以使用方便的类型提示(defn ^"[Ljava.lang.String;" function [ab])
:A
PersistentVector
can contain objects of any type, there is no way to enforce the type of the content, so a notation for such a type hint does not exist. You can have it return a Java array of strings and then you can use the convenience type hint(defn ^"[Ljava.lang.String;" function [a b])
: