I want to type hint an overloaded Java method. I used to have a function
like so

(defn iri [name]
 (IRI/create name))

Where IRI.create is one of 

IRI.create(String)
IRI.create(URL)
IRI.create(File)

Type hinting the return value of this is straight-forward, but the
parameter is one of three types. The only way I seem to be able to get
this to work is to do lots of instance? checks...


(defn ^IRI iri
  [name]
  (cond
   (instance? String name)
   (IRI/create ^String name)
   (instance? java.net.URL name)
   (IRI/create ^java.net.URL name)
   (instance? java.io.File name)
   (IRI/create ^java.io.File name)))

which is a lot longer and, well, just not very nice. I could make this
neater with a macro -- something like...

(with-types [String, URL, File]
   (IRI/create name))

which would expand into the cond form above. But the instance? checks
seem not ideal. Is there a better solution?

Phil

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to