3 ms·
>Where this technique is useful is cases where the method being called is impossible to know until runtime, such as in Ruby or Groovy. Scala, like Java, is not
by mattrepl 18y ago
>Where this technique is useful is cases where the method being called is impossible to know until runtime, such as in Ruby or Groovy. Scala, like Java, is not like this and the compiler can be guaranteed to have enough information to generate the right bytecode for the call inline.
What about polymorphic method calls? Statically typed or not, which method implementation to invoke is impossible to know until runtime.
http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming#Java http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented...
- allertonm 18y agoWhile the actual implementation method that will be invoked is unknown, in a statically typed language the base class/interface and the method signature are known. In Java/Scala classes the types of the arguments are baked into the method names used by the bytecode so this is important information from a performance point-of-view. Looking up this information at run-time (via reflection) is slow, but dynamic languages on the JVM have have been forced to do that when calling into Java classes from the dynamic language - which is the starting point of the original article. Scala is not affected by this because it is not a dynamic language and the Scala compiler has the exact same information that the Java compiler does when it compiles a call from Scala to Java.