How to fix a problem in Clojure

I have this function in a namespace that does not import / does not require / does not use other packages:

(defn crash [msg] (throw (Throwable. msg))) 

Cursive (IntelliJ IDEA IDE plugin) highlights Throwable and gives me the message Cannot disambiguate overloads of Throwable . I get the same message with Exception and Error .

I do not understand the source of this post - I doubt that these Java classes are defined in any other jar files except Java languages. Anything I can do to make this message disappear?

They are in project.clj :

  :dependencies [[org.clojure/clojure "1.6.0"] [net.mikera/imagez "0.8.0"] [org.clojure/math.numeric-tower "0.0.4"]] 
+5
source share
1 answer

Throwable has two 1-arg ( doc ) constructors: one expects a String , and the other expects a Throwable .

At run time, Clojure computes it (since in this particular case it is not possible for the object to be either String or Throwable ), but this requires the use of reflection.

Adding a hint type to msg to indicate which overload you expect to use will eliminate the need for reflection and hopefully calm Cursive down.

 (defn crash [^String msg] (throw (Throwable. msg))) 
+9
source

All Articles