clojure

How to type hint a float array?


This code

(GL33/glUniform2fv ^int (location shader "offsets") ^float [] offsets)

produces this error:

No matching method glUniform2fv found taking 3 args for class org.lwjgl.opengl.GL33

I've tried removing the space:

(GL33/glUniform2fv ^int (location shader "offsets") ^float[] offsets)

to no avail.

Clojure seems to be mistaking the ^float [] type hint for a parameter - but not the ^int type hint.

What can I do about that?


Solution

  • Pre Clojure 1.12

    As noted in the comments, floats is the way to type hint that symbol.

    ref: Type Aliases

    Post Clojure 1.12

    If using Clojure 1.12 or later, you can specify an array class of N dimensions by using Classname/N. For your purposes here, you can write float/1.

    ref: Java interop: Class access, Clojure 1.12 release notes