Which version of clojure? This works fine in 1.10

Clojure 1.10.0-master-SNAPSHOT
user=> (set! *warn-on-reflection* true)
true
user=> (definterface Interface (test []))
user.Interface
user=> (def p (proxy [Object Interface] [] (test [] 1)))
#'user/p
user=> (defn get-test [o] (.test ^Interface o))
#'user/get-test
user=> (get-test p)
1


> On 30 Jul 2018, at 11:26, Mark Engelberg <mark.engelb...@gmail.com> wrote:
> 
> Those fishy things were errors I made when simplifying and transcribing the 
> proxy to post, but I have it correct in my own code.
> 
> Here's a more precise, tested minimal example:
> 
> (definterface Interface (test []))
> (def p (proxy [Object Interface] [] (test [] 1)))
> (defn get-test [o] (.test ^Interface o))
> 
> => (get-test p)
> This throws an error that it can't cast the proxy to Interface.
> 
> If you remove the ^Interface type hint, then get-test will work but will 
> trigger reflection.
> 
> Thanks for looking at this. It seems like it should work, but it doesn't.
> 
> 
> On Mon, Jul 30, 2018 at 3:06 AM, Nicola Mometto <brobro...@gmail.com 
> <mailto:brobro...@gmail.com>> wrote:
> That's exactly what you should do and it does work, e.g.:
> 
> user=> (set! *warn-on-reflection* true)
> true
> user=> (.meta ^clojure.lang.IMeta (proxy [clojure.lang.IMeta] [] (meta [] {:a 
> 1})))
> {:a 1}
> 
> In your small example you have two errors that might be fishy: a missing arg 
> vector to pass to the super ctor and an extra `this` parameter in the method 
> impl (proxy, unlike reify, is anaphoric and binds `this` for you)
> 
> 
>> On 30 Jul 2018, at 10:56, Mark Engelberg <mark.engelb...@gmail.com 
>> <mailto:mark.engelb...@gmail.com>> wrote:
>> 
>> Let's say I have a proxy object:
>> 
>> (def p (proxy [MyClass MyInterface] (interfaceMethod [this] ...)))
>> 
>> Now, I want to call (.interfaceMethod p).  How do I do this without 
>> reflection?
>> I would have thought that (.interfaceMethod ^MyInterface p) would work, but 
>> this results in an error message that this proxy object cannot be cast to 
>> MyInterface.
>> 
>> 
>> 
>> -- 
>> 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 
>> <mailto: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 
>> <mailto:clojure+unsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en 
>> <http://groups.google.com/group/clojure?hl=en>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+unsubscr...@googlegroups.com 
>> <mailto:clojure+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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 
> <mailto: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 
> <mailto:clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> <http://groups.google.com/group/clojure?hl=en>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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 
> <http://groups.google.com/group/clojure?hl=en>
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to