Sirgeorge
Sirgeorge

Reputation: 137

java.lang.Class cannot be cast to clojure.lang.IFn when date capturing and string formatting

I'm not really seeing where I'm going wrong here, especially since I hit upon a minor variation at one point that allowed this, but couldn't explain why it worked. Please also tell me, in a more overall sense, what the issue is in general when you are having casting problems of a Java class to a Clojure Interface Function (IFn) and how you can debug it. Thank you.

(defn date
  []
  (new java.util.Date))

(defn x
  []
  (.format(java.text.SimpleDateFormat "YYYY-MM-DD")(new java.util.Date)))

Upvotes: 1

Views: 505

Answers (1)

Eugene Pakhomov
Eugene Pakhomov

Reputation: 10632

Add a . right at the end of SimpleDateFormat. Right now, you're calling the class as a function, hence that exception. Adding a dot at the end makes it an instantiation.

You can do the same with (new java.util.Date) - it can be replaced with (java.util.Date.).

Upvotes: 2

Related Questions