2011/1/16 Robert Campbell <rrc...@gmail.com>: > The second form - (.foo bar), expanded to (. bar foo) - eventually > calls Reflector.invokeNoArgInstanceMember.
For that form, the clojure compiler cannot infer the type of bar, and does not know which exact method (class + type signature) .foo represents. Due to this, a runtime lookup that uses the reflector is inserted, since a method invocation in java byte code must be statically typed (at least currently). > The first form - (.foo (new Bar)), expanded to (. (new Bar) foo) - > doesn't seem to use any Reflector _invocation_ methods. I also added a > breakpoint to java.lang.reflect.Method.invoke() and it never hits that > breakpoint. This is because the compiler knows the type of the arg to .foo, and can emit bytecode for a plain old (statically typed) method invocation. Since reflective method invocations are pretty slow, you often try to add type hints so that it can be avoided: (.foo ^Bar bar) The generated bytecode for this method invocation should be very similar (if not identical) to the bytecode for (.foo (new Bar)) // raek -- 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