Fork me on GitHub
#interop
<
2023-05-25
Crispin14:05:26

Hi there, Im trying to remove reflection on a ^bytes type hinted parameter to a java call. If I type hint the byte-array directly, it works, but if I type hint a (when ..) to enable a null to be passed in, the reflection cant find the call, and thinks its a java.lang.Object, not a bytes! Any idea what is going on here and how to type hint this correctly?

Crispin14:05:59

code that works:

(KeyPair/load
      ^JSch (references/get-instance agent)
      ^bytes (utils/decode-base64 private-key-bytes)
      ^bytes (utils/decode-base64 public-key-bytes))

Crispin14:05:33

code that doesn't:

(KeyPair/load
      ^JSch (references/get-instance agent)
      ^bytes (when private-key-bytes (utils/decode-base64 private-key-bytes))
      ^bytes (when public-key-bytes (utils/decode-base64 public-key-bytes)))

Crispin14:05:50

results in a call to static method load on com.jcraft.jsch.KeyPair can't be resolved (argument types: com.jcraft.jsch.JSch, java.lang.Object, java.lang.Object).

Crispin14:05:07

suddenly they are java.lang.Object which is wrong

Crispin14:05:31

(the code works with reflection... I just would like to remove it)

Alex Miller (Clojure team)14:05:46

you might want to pull the expr out into a let

Crispin15:05:11

alright, yeah that now resolves the right static method.

Crispin15:05:34

Is it because when is a macro?

Crispin15:05:49

somehow loses the metadata?