interop

dharrigan 2025-07-26T20:14:26.622029Z

At the moment, I'm trying to remove a reflection warning, namely call to java.util.HashSet ctor can't be resolved.. I'm doing this:

dharrigan 2025-07-26T20:15:21.401159Z

A moment, whilst I get the right clojure...

dharrigan 2025-07-26T20:15:52.935799Z

(->> results
                 (map build-credential-id)
                 (HashSet/new))

dharrigan 2025-07-26T20:16:29.392449Z

I've tried type hinting all over the place, but to no avail (even type hinting the return type of build-credential-id (which is returning a Java class)

dharrigan 2025-07-26T20:16:53.762499Z

The only way I could remove the type hint is this:

dharrigan 2025-07-26T20:16:56.431459Z

(let [hashset (HashSet.)]
              (->> results
                   (map build-credential-id)
                   (.addAll hashset))
              hashset))

Alex Miller (Clojure team) 2025-07-26T20:30:53.736279Z

You could use param-tags on HashSet/new - that makes it explicit

Alex Miller (Clojure team) 2025-07-26T20:31:40.595439Z

(^[Collection] HashSet/new)

Alex Miller (Clojure team) 2025-07-26T20:31:56.175989Z

Not sure if that’s the right type but whatever that should be

Alex Miller (Clojure team) 2025-07-26T20:32:24.235329Z

That will either work without reflection or throw, never reflects

dharrigan 2025-07-26T20:34:07.313349Z

Hmm, you know I did try that, let me try again

dharrigan 2025-07-26T20:34:34.235209Z

(I reviewed the interop page before coming here and tried the Clojure 1.12 new thingie πŸ™‚ )

dharrigan 2025-07-26T20:37:27.021279Z

That seems to make the clojure compiler complain:

dharrigan 2025-07-26T20:37:29.560789Z

(->> results
                 (map build-credential-id)
                 ([^PublicKeyCredentialDescriptor] HashSet/new))

dharrigan 2025-07-26T20:38:08.739889Z

Unmatched delimiter: ]

dharrigan 2025-07-26T20:40:23.972719Z

sorry, my mistake, had the caret in the wrong place πŸ™‚

dharrigan 2025-07-26T20:41:37.455039Z

Ended up with this:

dharrigan 2025-07-26T20:41:39.489559Z

; (err) Syntax error (IllegalArgumentException) compiling HashSet/new at (src/repository.clj:101:18).
; (err) Error - param-tags [com.yubico.webauthn.data.PublicKeyCredentialDescriptor] insufficient to resolve constructor in class java.util.HashSet

dharrigan 2025-07-26T20:42:05.726929Z

From

dharrigan 2025-07-26T20:42:07.645129Z

(->> results
                 (map build-credential-id)
                 (^[PublicKeyCredentialDescriptor] HashSet/new)))

dharrigan 2025-07-26T20:42:59.728909Z

Oooh, I see, if I put it like this ^[Collection] it works

dharrigan 2025-07-26T20:44:02.612369Z

Wunderbar. Thank you! πŸ™‚ I got there in the end, with a bit of hinting, ta πŸ™‚

dharrigan 2025-07-26T20:44:40.506989Z

Working without reflection warning:

dharrigan 2025-07-26T20:44:42.349579Z

(->> results
                 (map build-credential-id)
                 (^[Collection] HashSet/new)))

dharrigan 2025-07-26T20:44:50.273429Z

.

dharrigan 2025-07-26T20:17:00.871519Z

but that feels very wrong

dharrigan 2025-07-26T20:17:11.229219Z

Any hints (pun intended! πŸ™‚ )?