【问题标题】:Can I hint a function's parameter type in deftype?我可以在 deftype 中提示函数的参数类型吗?
【发布时间】:2012-10-28 07:37:24
【问题描述】:

我试图这样做:

(defprotocol TestP
  (fun [this ^int i]))

(deftype Test [] TestP
  (fun [this ^int i] i))

但是,编译失败并显示Can't find matching method: fun。这是否意味着 deftype 函数可能不接受参数类型提示?

【问题讨论】:

  • 仅供参考。如果你想要静态类型的 Java 接口,你可以使用definterfacestackoverflow.com/questions/7770282/…
  • 非常感谢 tnoda,你的答案其实就是我一直在寻找的答案

标签: clojure


【解决方案1】:

您不需要在deftype 中指定类型提示,因为错误消息明确指出:

找不到匹配方法:好玩,不要提示自动匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    • 2014-07-09
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多