Domanda

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)))
È stato utile?

Soluzione

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))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top