Search code examples
clojurejvmlispclojure-repl

Clojure: Why can't I reference class methods without calling them?


Here's a Clojure REPL session:

moon.core> Double
java.lang.Double
moon.core> (Double/parseDouble "1.0")
1.0
moon.core> Double/parseDouble
CompilerException java.lang.RuntimeException: Unable to find static field: parseDouble in class java.lang.Double, compiling:(*cider-repl moon*:1:7159) 

I'm able to reference Double, and I'm able to call Double/parseDouble, but I can't directly reference it. I see the same result for other class methods in the Java standard library (e.g. Math/abs, Integer/parseInt). the Why is that?


Solution

  • This doesn't work (in the REPL or otherwise), because there is no static field called parseDouble on the Double class. parseDouble is a method. You can call it, but you can't access it like a field.