Clojure warn-on-reflection and type hints
- by Ralph
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).