I'm using proxy in Clojure to extend a Java class. I need to set a field in the superclass, how can i do this? The code below doesn't work.

(proxy [BasicPlayer] []
  (open [url]
  (set! super/m_dataSource url)))
有帮助吗?

解决方案

From the documentation for proxy:

Note that while method fns can be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied.

Sorry, but it sounds like you're out of luck. You can call protected superclass methods with proxy-super, but I think that's about it.

You might have better luck with gen-class. Something along the lines of:

(ns my.Player
  (:gen-class
   :extends BasicPlayer 
   :exposes {m_dataSource {:set -setDataSource}})

(defn -open [this url]
  (-setDataSource this url))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top