I think that what happens is that the new { ... } objects are structured, which requires reflection to be implemented.
The main reason is that Scala structural typing allows objects to be processed as if they were instances of many types according to the methods that they actually have (for example, duck printing). The JVM allows you to use only one type, so methods that are not part of the base type of an object must be accessible through something other than a regular call to a virtual method. The mechanism used in this case is a reflection.
When the Scala compiler sees a call to a method called on a structurally typed object, it (modulo some optimizations) translates the method call, for example:
af(b, c)
to
a.getClass .getMethod("f", Array(classOf[B], classOf[C])) .invoke(a, Array(b, c))
An example taken from the place where the technique was described .
The Scala team decided to apply a selection policy for advanced features that everyone might not use. reflectiveCalls is one of them, as described in this SIP
mrmcgreg
source share