Search code examples
clojureclojure-java-interop

Java Interop: Why does (.setProperty (Properties.) "key1" "value1") return nil but wrapping the call in a doto works?


The following code returns nil:

(.setProperty (Properties.) "key1" "value1") -> nil

The following, however, seems to work as intended:

(doto (Properties.) (.setProperty "key1" "value1")) -> {"key1" "value1"}

Why is that?


Solution

  • .setPropertyreturns the previous value, or null if one did not exist. Since it is operating on a new Properties instance, this is nil. (doto x f) evaluates f with x in the first argument position and then returns x. In this case the nil returned by setProperty is ignored and the modified Properties instance is returned.