From JDK19+ onwards, the following won't work without adding a type hint:
(def x 10)
(Thread/sleep x)
The tricky bit is that in earlier JDKs the above would work without adding type hints, but as soon as you upgrade your programs start to fail.
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
?