Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in Clojure by

When calling a method on an instance of a Java class that takes a Collection<? extends Something> as the argument, I've tried the following:

(.theMethod ^SomeClass inst ^Collection [thing1 thing2])

Unfortunately, when I'm using lein check this gives me a reflection warning of:

call to method theMethod on example.SomeClass can't be resolved (argument types: clojure.lang.IPersistentVector).

I can fix this by binding it to a symbol with a type hint:

(let [^Collection things [thing1 thing2]]
  (.theMethod ^SomeClass inst things))

What is going on that the literal vector can't be type-hinted in place?

1 Answer

+1 vote
ago by

Literal collections are tagged as IPersistentVector, IPersistentMap, etc and as constant expressions won’t preserve type hints. It is better here to use the new qualified method syntax with param-tags hints if needed.

...