I was writing a client/server test, and ran into something unexpected. In the following code, the port argument of the Socket
constructor isn't able to be inferred:
(ns second-try.test.client
(:import [java.net Socket]))
(def port 5555)
(defn -main []
; "Cannot disambiguate overloads of Socket"
(let [sock (Socket. "127.0.0.1" port)]))
The type of the first argument should be obvious since I'm passing a literal. I would think the type of the port would be obvious too since again, it's just a literal; albeit one tucked away behind a def
.
For some reason though, it can't figure out the type of port
. I can remedy it by putting an annotation on either the def
, or in front of the argument, but why is this necessary? Shouldn't it be obvious to it what the type is?