I figured out the problem and thought I'd note it here.

When you "proxy" and object, the proxy code calls the constructor of
the object BEFORE it registers its own methods as overrides for the
object's methods.  If the constructor calls methods, they'll be its
own implementations rather those of the proxy.

Bottom line, if the object you're proxying does a lot of work in its
constructor using methods in its class, the proxy's methods won't be
called. If one of those methods is abstract, you're screwed.

The code I'm working with, though, does this all over the place.

I ended up having to write some Java that wrapped an inner subclass of
the offending class, and used Clojure to implement an interface which
the inner class can use.

Keith

On Fri, Dec 11, 2009 at 4:18 PM, Keith Irwin <keith.ir...@gmail.com> wrote:
>
>
> On Dec 11, 3:31 pm, ataggart <alex.tagg...@gmail.com> wrote:
>> On Dec 11, 12:27 pm, Keith Irwin <keith.ir...@gmail.com> wrote:
>
>> > Folks--
>>
>> > I've got a class I can't change which has an abstract method I'd like
>> > to override using the proxy macro in Clojure.
>>
>> > The class looks something like:
>>
>> > public abstract class Foo {
>>
>> >    private Map stuff;
>>
>> >    private void initStuff() {
>>
>> >        stuff = new HashMap();
>> >        stuff.put("a", new Object());
>> >        addStuff(stuff);
>> >    }
>>
>> >    protected void abstract addStuff(Map stuff);
>> >  }
>>
>> > Normally, you extend the above and implement the addStuff method.
>> > Works in Groovy as long as I explicitly state the void return type and
>> > the type of the parameters.
>>
>> > In Clojure, I construct:
>>
>> >    (proxy [Foo] []
>> >       (addStuff [stuff] (println "yay!")))
>>
>> > But get an AbstractMethodError when I attempt to use the Foo class
>> > (calling a method which eventually calls addStuff).
>>
>> > The docs suggest I can override a protected method class, but can't
>> > call other protected methods, which I think is fine, here.
>>
>> > Is there something I'm missing?
>>
>> > Keith
>
>> Given what you have written, the proxy function will return an
>> instance that extends Foo, implementing the addStuff method; it
>> doesn't modify the Foo class, nor provide you with a derived class.
>> If you want to create a derived class that's accessible from java,
>> you'll need to use something related to gen-class.
>
> I was under the impression that :gen-class only works for AOT
> compilation, rather than running in a scripting context. Maybe the
> solution is to add a little Java to the mix. The unfortunate part of
> all this is that I HAVE to use the something like the above class due
> to Politics.
>
> Thanks!
>
> Keith
>
> --
> 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 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

Reply via email to