Thanks for the responses Ambrose and Gary, I suppose the answer is its dependent on JVM implementation/version. As Gary pointed out his code broke on the JVM upgrade. The real question is, if there is ambiguity what "should" the behaviour be? It seems far from ideal atm, brodering on non-deterministic. One option would be to throw a RuntimeException if multiple methods match.
On Tuesday, June 11, 2013 3:14:46 PM UTC+1, Ambrose Bonnaire-Sergeant wrote: > > Hi Nathan, > > I just had a quick look at the implementation: I think Clojure picks the > first matching method if several are found. > > > https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Reflector.java#L70 > > It's probably worth testing this out though. > > Thanks, > Ambrose > > > On Tue, Jun 11, 2013 at 9:24 PM, N8Dawgrr <nathan.r...@gmail.com<javascript:> > > wrote: > >> Hi All, >> >> I have a question regarding ambiguity in reflective dynamic invocation. >> >> In Clojure you can dynamically invoke a method on a Java class like so: >> >> (. some-instance bar arg) >> >> where bar is a method name. >> If the type inferencer can't ascertain the type of some-instance a >> runtime reflective path is used to perform the method invocation. >> Lets suppose some-instance is of type Foo which has two overloads of >> method bar: >> >> bar(Apple arg) >> >> and >> >> bar(Orange arg) >> >> Now lets suppose Apple is an interface which extends Fruit and so is >> Orange. >> >> Now lastly lets suppose we have a class MutantFruit which implements BOTH >> Apple and Orange. >> >> My question is what method is invoked at runtime for the following code: >> >> (. some-instance bar mutant) >> >> where mutant is an instance of MutantFruit >> >> Regards, >> >> Nathan >> >> -- >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- -- 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/groups/opt_out.