Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

5.
Command chains • A grammar improvement allowing you to drop dots & parens when chaining method calls –an extended version of top-level statements like println • Less dots, less parens allow you to –write more readable business rules –in almost plain English sentences • (or any language, of course)5

53.
Controlling code execution • Your application may run user’s code – what if the code runs in inﬁnite loops or for too long? – what if the code consumes too many resources? • 3 new transforms at your rescue – @ThreadInterrupt: adds Thread#isInterrupted checks so your executing thread stops when interrupted – @TimedInterrupt: adds checks in method and closure bodies to verify it’s run longer than expected – @ConditionalInterrupt: adds checks with your own conditional logic to break out from the user code18

62.
Compilation customizers • Ability to apply some customization to the Groovy compilation process • Three available customizers –ImportCustomizer –ASTTransformationCustomizer –SecureASTCustomizer • But you can implement your own25

77.
Underscore in literals • Now we can also add underscores in number literals for more readability long creditCardNumber = 1234_5678_9012_3456L long socialSecurityNumbers = 999_99_9999L float monetaryAmount = 12_345_132.12 long hexBytes = 0xFF_EC_DE_5E long hexWords = 0xFFEC_DE5E long maxLong = 0x7fff_ffff_ffff_ffffL long alsoMaxLong = 9_223_372_036_854_775_807L long bytes = 0b11010010_01101001_10010100_1001001039

79.
InvokeDynamic • Groovy 2.0 supports JDK 7’s invokeDynamic –compiler has a ﬂag for compiling against JDK 7 –might use the invokeDynamic backport for < JDK 7 • Beneﬁts – more runtime performance! • at least as fast as current « dynamic » Groovy –in the long run, will allow us to get rid of code! • call site caching, thanks to MethodHandles • metaclass registry, thanks to ClassValues • will let the JIT inline calls more easily41

111.
Static Compilation • Given your Groovy code can be type checked... we can as well compile it « statically » –ie. generate the same byte code as javac • Also interesting for those stuck in JDK < 7 to beneﬁt from performance improvements58