我想确保我在浮点数组上使用未装箱和未反射的算术,但我无法编译它。
如何在这样的函数中输入提示浮点数?
(defn ff2a
^"[F" ; Return type hint for a float array
[^float f1 ^float f2] ; Argument type hints
(float-array [f1 f2]))
当我尝试将其加载到 REPL 中时,出现此错误:
Syntax error (IllegalArgumentException) compiling fn* [...] Only long and double primitives are supported
你不能。这个错误是很明显的。即使这样也失败了:
user=> (defn f [^float x])
Syntax error (IllegalArgumentException) compiling fn* at (REPL:1:1).
Only long and double primitives are supported
您仍然可以使用未装箱的双打。如果这对您不起作用,最好用 Java 实现这个特定部分。