Factor Clojure code setting many different fields in a Java object
- by chris
How do I factor code setting many different fields in a Java object? I would like to factor
(set! (. employee name) "Chris")
(set! (. employee age) 100)
(set! (. employee salary) 5000)
to
(doseq [field '((name "Chris") (age 100) (salary 5000))]
(set! (. employee (first field)) (second field)))
However this won't work because the period is a macro, and tries to evaluate (first field) literally. By the way, I understand that setting fields is not good practice. I need to inter-operate with legacy code.