|Groovy 4 Improves Query Support|
|Written by Kay Ewbank|
|Monday, 07 February 2022|
Groovy 4 has been released with improvements including a new query language and support for switch expressions. The developers describe it as being designed for JDK8+ with much improved JPMS support. Groovy is an optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform.
The aim of Groovy is to improve developer productivity because of its concise, familiar and easy to learn syntax. The developers say it integrates smoothly with any Java program, and delivers powerful features including scripting capabilities, Domain-Specific Language authoring, runtime and compile-time meta-programming and functional programming.
The latest release has been reworked to include the most important recent additions to Java, starting with support for switching. Switch expressions were added to Java in version 13, and Groovy developers can now make use of them. The release notes point out that
"Groovy has always had a very powerful switch statement, but there are times when a switch expression would be more convenient."
Groovy's switch expressions borrow heavily from Java, without the requirement that all possible values of the switch target are covered by case branches. If no default branch is present, an implicit one returning null is added. However, the developers say that in future Groovy versions, or perhaps through tooling like CodeNarc, they expect to support the stricter checking of exhaustive case branches similar to Java.
The next addition is a Java equivalent of GroovyShell, allowing to more easily work with snippets of Java code.
The next major addition is support for records, as introduced in Java 14. Groovy already had some support for records via features like the @Immutable and @Canonical AST transformations.
Groovy 4 adds support for native records for JDK16+ and also for record-like classes (also known as emulated records) on earlier JDKs. Record-like classes have all the features of native records but don’t have the same information at the bytecode level as native records, and so won’t be recognized as records by a Java compiler in cross-language integration scenarios.
A new query language, GINQ, a.k.a. Groovy-Integrated Query or GQuery has been also been added.GQuery supports querying collections in a SQL-like style. The developers say this could involve lists and/or maps or your own domain objects or those returned when processing for instance JSON, XML and other structured data. The team has plans to further develop GINQ to add GQuery support for SQL databases where an optimized SQL query is generated based on the GQuery expression much like Groovy’s DataSet functionality.
Groovy 4 is available now.
or email your comment to: email@example.com
|Last Updated ( Monday, 07 February 2022 )|