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

0 votes
ago in Java Interop by

Hi,

I noticed some reflection warning that goes away when removing a hint from fn arguments. I would like to understand the reason for this.

Example, loading this code

(set! *warn-on-reflection* true)

(defn duration-of-seconds
  (^java.time.Duration [^long seconds]
   (java.time.Duration/ofSeconds seconds)))

(defn sleep
  [seconds]
  (Thread/sleep (duration-of-seconds seconds)))

Raises a reflection warning:

call to static method sleep on java.lang.Thread can't be resolved (argument types: java.lang.Object).

However, just removing the ^long hint from the duration-of-seconds fn argument, makes the reflection warning go away.

Thanks!

ago by
What Java version are you using? Thread/sleep gained the Duration overload in Java 19, so it matters.
ago by
Java 25. Indeed, I used that method for the minimal example above precisely because of the overload in recent versions.

1 Answer

...