From JDK19+ onwards, the following becomes reflective without adding a type hint:
(def x 10)
(Thread/sleep x)
The tricky bit is that in earlier JDKs the above did not reflect, but when you upgrade your JDK, the reflection starts.
If using native-image, your program may start to fail due to missing reflection configuration.
It would be nice to have a built-in sleep function that accepted a number so we don't forget to add type hints and it would work consistently across JDKs.
E.g.:
(ns clojure.java.misc)
(defn sleep [x]
(if (number? x)
(Thread/sleep (long x))
....)
A better name for clojure.java.misc
is welcome. Maybe just clojure.java
or put this function into clojure.core
?