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

Time:05-26

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)))

CodePudding user response:

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.).

  • Related