interop 2023-04-21

Does it make sense to type hint a Java interface vs. a concrete class? I have clojure code that is going to be passed some sort of Iterable that I don't know ahead of time so I was wondering if I should do:

(let [^Iterable i (:val m)]
    ...
    (.size i))
to avoid reflection on the .size call.

Alex Miller (Clojure team) 2023-04-21T18:00:59.865539Z

Yes, usually better

Alex Miller (Clojure team) 2023-04-21T18:01:40.160599Z

Although Iterable doesn’t have a size method

Thanks. And also, good point.