def sample = ['Groovy', 'Gradle', 'Grails', 'Spock'] as String[]
def result = sample.stream() // Use stream() on array objects
.filter { s -> s.startsWith('Gr') }
.map { s -> s.toUpperCase() }
.toList() // toList() added to Stream by Groovy
when the application hasn’t used lambda expressions before, even the framework for generating the lambda classes has to be loaded (Oracle’s current implementation uses ASM under the hood). This is the actual cause of the slowdown, loading and initialization of a dozen internally used classes, not the lambda expression itself.
Serialization of inner classes, including local and anonymous classes, is strongly discouraged. When the Java compiler compiles certain constructs, such as inner classes, it creates synthetic constructs; these are classes, methods, fields, and other constructs that do not have a corresponding construct in the source code. Synthetic constructs enable Java compilers to implement new Java language features without changes to the JVM. However, synthetic constructs can vary among different Java compiler implementations