Skip to content

Instantly share code, notes, and snippets.

@daniellansun
Created May 11, 2019 17:30
Show Gist options
  • Save daniellansun/7d3d55c2645e6040c779db17f25e3f2f to your computer and use it in GitHub Desktop.
Save daniellansun/7d3d55c2645e6040c779db17f25e3f2f to your computer and use it in GitHub Desktop.
// Show some new features of Groovy3
// The complete new feature list can be found at:
// https://github.com/danielsun1106/groovy-parser
@groovy.transform.CompileStatic
def helloGroovy3() {
File f = new File("D:/hello-groovy${1 + 2}.txt")
try (Writer out = new FileWriter(f)) { // try-with-resources
out <<
['hello', 'groovy3', 'Hello', 'Groovy3'].stream()
.filter(e -> !Character.isLowerCase(e[0] as char)) // lambda expression
.map(String::toUpperCase) // method reference
.toArray(String[]::new) // constructor reference
.join(', ')
}
assert 'HELLO, GROOVY3' == f.text
}
helloGroovy3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment