#groovy3
Explore tagged Tumblr posts
adamldavis · 6 years ago
Text
Groovy 2.5 & 3
If you have followed me for any time, you know I'm a big fan of Groovy, the super-Java-like language that runs on the JVM. You've probably heard of it, maybe you even use it, but what is less known is that it's constantly evolving and has some great new features coming soon (or already here). Inspired by some recent news, here's all about Groovy 2.5 and 3.                                                                                                                                                                                 Updates in Groovy 2.5 Groovy 2.5 added support for JDK9+, added 11 new AST transformations, and added the macro feature which makes writing AST transformations much easier.                                                                                                                                                          The annotations added in Groovy 2.5 include: @AutoFinal, @AutoImplement, @ImmutableBase, @ImmutableOptions, @MapConstructor, @NamedDelegate, @NamedParam, @NamedParams, @NamedVariant, @PropertyOptions, and @VisibilityOptions. - @AutoImplement: Automatically implements missing abstract methods (such as those from an Interface). You can specify an Exception to throw from those methods such as UnsupportedOperationException. It can be useful for generating test stubs or when you only need to implement a subset of inherited abstract methods. - @AutoFinal: Automatically adds final modifier to method parameters. - @MapConstructor: Adds a constructor to your class that has one Map parameter and expects field-names as keys and sets the corresponding field values. Also many annotations were improved with additional attributes. For example, @TupleConstructor now includes seven more attributes. The @Immutable annotation was updated to recognize the Date/time classes added in Java 8 are immutable, and to handle Optional. Updates in Groovy 3 Groovy 3 sports a completely rewritten parser that brings Groovy up to parity with the latest Java 11 syntax along with new Groovy-only features. It runs on JDK 8 minimum and has better support for JDK 9/10/11. The Java-like syntax now includes Java-style lambda expressions and method references, array initialization, and do/while loops, which have eluded Groovy for many years. Edit: There is hope that in the near future after working out some issues* The new parser also compiles to "indy" by default which uses Java's invokedynamic feature. This has been available for years, but was not the default before. This, along with other changes, makes Groovy code more performant. New Operators Identity: === can now be used to express identity-equal and !== and not identity-equal. Since Groovy interprets == as ".equals", it used ".is" for identity-equals in the past. The support of "===" should avoid some confusion. This is similar to JavaScript's === operator. Negative variants of operators: !instanceof and !in are now supported. This will simplify the syntax in these situations. Before you would have to type !(x instanceof Date) whereas now you can simply type x !instanceof Date. Elvis Assignment: You may be familiar with the elvis operator (?:) in Groovy. In many cases you would use this operation to provide a default when assigning a value. For example: name = name ?: 'None'. Now you can shorten this expression to have the same meaning in Groovy 3 with the following: name ?= 'None' Safe indexing: Much like the safe-reference operator, there is now a safe-indexing operator, ?. This allows you to access an index of an array (or List), but if the array is null, it will return null instead of throwing an exception. For example the following would set the value to the first value of the array, or null if the array is null: value = array?[0] Java Parity Groovy 3 support new features added from Java 8 to 11, such as lambda expressions, method references, constructor references, and even local variables (var). All flavours of lambda expressions are supported (and currently compiled to Closures): - No parameters: () -> expression - Single paramter: x -> expression - Explicit return is optional: (x, y) -> { x * y } - Types are allowed: (int x, int y) -> { return x + y } - Default values are allowed: (int x, int y = 10) -> x+y There's much more..... in fact, I'm working on updating my book, Learning Groovy, and releasing a second edition later this year, so stay tuned! Conclusion As you can see there's a ton to be excited about with Groovy 3. Groovy 3.0.0-alpha-4 is available right now so go check it out. Learn more: groovy.apache.org
0 notes
dudewhoabides · 3 years ago
Text
4 notes · View notes
quickberater · 5 years ago
Text
0 notes
adamldavis · 6 years ago
Text
Gr8Conf EU 2019
I had the great privilege of leading a workshop and two talks at Gr8Conf EU 2019 in Copenhagen, Denmark. This was also my first time attending Gr8Conf EU (I did attend Gr8Conf US 2017). My life has finally quieted down enough now that I can write about my experience.
The conference was, in a word, great. I saw a few familiar faces, like Paul King, Jeff Scott Brown, Michael Carducci, Sergio del Amo Caballero, and Jeff Beck (all of whom I've seen before, mostly as just another audience member), and met some great new people whom I've never seen before but who certainly left a lasting impression that I won't soon forget like Vladimír Oraný, Szymon Stepniak, Jennifer Strater, Charlotte Mays, and others. For an extremely introverted person such as myself, I don't often talk to so many people at one time, and I'm grateful for the opportunity to converse and openness of everyone at this conference. (The coffee and food was great too!)
There were too many great talks to list, but some highlights for me were Paul King's keynote on Groovy 2.5, 3 and 4 (which is available online), Jesper Steen Møller's talk, "Reactive Web APIs with Micronaut" (which brilliantly showed how to use Reactive Streams within a micronaut based microservice including a demo of how to use a backpressure strategy), and the "Running a developer's blog" talk by Szymon Stepniak (I hope to use some of his suggestions in the future if I ever get the time).
Oh and I did some talks too. Eventually these should make it onto youtube, but it might be many months. For now you can check out my github repo (https://github.com/adamldavis/2019-gr8conf) which has all of the code related to my talks/workshop plus a bit more. I tweeted out the slides at some point but it's up to you to find them. Just kidding. Here (https://www.slideshare.net/adam1davis/).
It was a really great conference and Copenhagen is beautiful. I hope to return again next year (or maybe in two years if not next year).
Meanwhile, I'm finished with the final updates to "Learning Groovy 3" which should be released later this year! I worked on this for several months this year and my technical reviewer gave me some great feedback so it should be a good one. In addition to updating the book for Groovy 3.0 and Grails 3.3, I've also updated and polished additional areas of the book based on my personal understanding of Groovy and things that have changed over the years.
1 note · View note