The problem here is that you're not giving the Clojure type inferencing enough info to work with and it's using reflection to find the correct method. When it finds multiple potential matching methods by arity, it calls an arbitrary one (not my favorite behavior). So, not a feature and maybe a bug (or maybe just "undefined behavior", depending how you think about it).
The start of the problem is that br is not automatically given a type - it's just treated as an Object. So the method getBaseNullSupplier is invoked reflectively and the return type of that is just defaulted to Object, which means it will reflectively find multiple matches for method_ and may call any of them. The simplest fix is to tag your br var with it's type: (def ^SupplierRouter br (new SupplierRouter)) Then the inferencer can figure out the rest of it automatically. Alternately, you could tag just the first call with br: (println (. br method_ (. ^SupplierRouter br getBaseNullSupplier))) And that should be enough as well. If this was in a function, I would tag the incoming parameter instead. On Sunday, November 6, 2016 at 10:02:42 AM UTC-6, Alexey Stepanov wrote: > > Hello! > > I experimented with overload resolution. And faced with a strange > behavior. > > https://gist.github.com/alejes/355881c1711224d5a773fbf0275b4898 > > The Clojure code calls a method from the Java. But at different runs I get > the result call different methods (4 and 6). > It is a simplified version of the example which I encountered. In the > original version it periodically called method #0. However, in the > simplified example I is not noticed call #0 method. > > It is a bug or feature? Can someone explain why is this happening? > > Thanks. > -- 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.