Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created September 22, 2015 14:27
Show Gist options
  • Save Chouser/a571770f06ef2a9c5334 to your computer and use it in GitHub Desktop.
Save Chouser/a571770f06ef2a9c5334 to your computer and use it in GitHub Desktop.
Clojure array type hint
(defn array-type
"Return a string representing the type of an array with dims
dimentions and an element of type klass.
For primitives, use a klass like Integer/TYPE
Useful for type hints of the form: ^#=(array-type String) my-str-array"
([klass] (array-type klass 1))
([klass dims]
(.getName (class
(apply make-array
(if (symbol? klass) (eval klass) klass)
(repeat dims 0))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment