>From: more-speech-6973 at 07/29/22 11:59:18 on wss://nostr-relay.untethr.me
>---------------
>Hello sir, could you explain why do use ^WebSocket to annotate conn with metadata?
You mean in the source code? Clojure sometimes needs to know the type of an object especially if you are going to call a java method on that object. So ^WebSocket tells clojure that the following object is of type WebSocket, and that allows clojure to properly call methods.
Here's an example. In the 'send-to' method I need to call the 'sendText' method to the WebSocket object. But there are many classes that have 'sendText' methods, and clojure has no way of knowing what class the 'conn' variable is, unless I tell it.
(defn send-to [^WebSocket conn msg]
(try
(let [msg (events/to-json msg)]
(println "sending:" msg)
(.sendText conn msg true))
(catch Exception e
(prn 'send-to (.getMessage e)))))
I hope this answers the question. Interoperating between clojure and Java is usually a joy; but every once in awhile you run into things like this and you have to use type coersions, like ^WebSocket, to resolve them.