Groovy 4.0.0 adds SQL-like querying

Groovy-integrated queries, sealed types, and switch expressions make their debut in the latest upgrade of the popular JVM language.

Groovy 4.0.0 adds SQL-like querying
Thinkstock

Groovy 4.0.0 has arrived as a production release. The latest upgrade to the JVM-based language introduces new SQL-like query capabilities, sealed types, and switch expressions.

GINQ, also known as Groovy-integrated Query or GQuery, is an incubating feature in Groovy 4.0.0. It supports querying collections in a SQL-like style. This might involve lists or maps, domain objects, or collections returned when processing such as JSON, XML, and other structured data. In a future version of Groovy, plans call for GQuery support for SQL databases where an optimized SQL query is generated based on the GQuery expression.

Groovy 4.0.0 also debuts sealed types and switch expressions. Sealed types, which restrict which other classes or interfaces may extend or implement them, can be used in instances such as creating enhanced enum-like hierarchies. With switch expressions, Groovy gains a convenient programming alternative to switch statements, which Groovy already has had, according to release notes.

Announced January 28 by the Apache Groovy team, Groovy 4.0.0 can be downloaded from groovy.apache.org. Other capabilities in Groovy 4.0 include:

  • Native records for Java Development Kit (JDK) 16 and record-like classes, also known as emulated records, are incubating features. Record-like classes have features of native records but do not have the same information at the bytecode level as native records; thus, they will not be recognized as records by a Java compiler in cross-integration scenarios.
  • Some select type checkers are bundled within the optional groovy-typecheckers module to encourage further use of the extensible type-checking mechanism.
  • Select macro methods are bundled within the optional groovy-macro-library module to encourage further use of macros.
  • A JavaShell feature, also in an incubating state, enables developers to more easily work with snippets of code. This capability is the Java equivalent of GroovyShell.
  • POJO annotation is featured in an incubating state.
  • An optional, incubating Groovy contracts module supports a design-by-contract style of programming. It provides contract annotations supporting the specification of class-invariants, pre-conditions, and post-conditions on Groovy interfaces and classes.
  • TOML (Tom’s Obvious Minimal Language) files are supported, also an incubating feature.
  • GString performance has been improved.

Copyright © 2022 IDG Communications, Inc.

How to choose a low-code development platform