Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure type hint for Map.Entry

What is the syntax for a type hint for java.util.Map.Entry, a nested static inner class, in Clojure 1.2?

I tried both ^Map/Entry and ^Map.Entry, and neither will compile.

like image 381
Ralph Avatar asked Feb 07 '11 13:02

Ralph


2 Answers

Found it!

(ns com.example
  (:import [java.util Map Map$Entry]))

(let [^Map$Entry foo ...])

and for type-hinting an Object[]:

(let [^"[Ljava.lang.Object;" foo ...])

BTW, that's some ugly syntax. Is there a better way?

like image 154
Ralph Avatar answered Sep 24 '22 13:09

Ralph


Inner classes are referred by $ sign, so, in this case, you can refer to it from Clojure as Map$Entry.

like image 21
Marko Avatar answered Sep 23 '22 13:09

Marko