Clojure warn-on-reflection and type hints

Posted by Ralph on Stack Overflow See other posts from Stack Overflow or by Ralph
Published on 2011-01-09T17:10:59Z Indexed on 2011/01/09 20:53 UTC
Read the original article Hit count: 159

Filed under:
|

In the following code, I am getting a warning on reflection:

(ns com.example
  (:import
    [org.apache.commons.cli CommandLine Option Options PosixParser]))

(def *help-option* "help")
(def *host-option* "db-host")

(def *options*
  (doto (Options.)
    (.addOption "?" *help-option* false "Show this usage information")
    (.addOption "h" *host-option* true "Name of the database host")))

(let
  [^CommandLine command-line (.. (PosixParser.)
                               (parse *options* (into-array String args)))

   db-host (.getOptionValue command-line "h")]  ; WARNING HERE ON .getOptionValue
  ; Do stuff with db-host
)

I have a type hint on command-line. Why the warning?

I am using Clojure 1.2 on OS X 10.6.6 (Apple VM).

I assume that I do not get a warning on (.addOption ...) because the compiler knows that (Options.) is a org.apache.commons.cli.Options).

© Stack Overflow or respective owner

Related posts about clojure

Related posts about type-hinting