«Truth can only be found in one place: the code.»
In my last project, we used Grails 3 that uses groovy as the main technology. With groovy you can really focus on your business problems. You have very little boilerplate code.
Here it is some cool stuff I really like in groovy.
Working with strings:
def text = 'Groovy is awesome!'
assert text[10..16] == 'awesome'
assert text - ' is awesome!' == 'Groovy'
assert text[0].isLetter()
assert text[0].isUpperCase()
assert text[6].isWhitespace()Working with lists and maps:
List emptyList = []
def countries = ["England", "Switzerland", "France"]
assert countries[1] == "Switzerland"
countries << "Italy"
assert countries.contains("Italy")
Map emptyMap = [:]
def country = [name: "Switzerland", capital: "Bern", population: 8211700]
assert country.name == "Switzerland"The elvis operator is very useful:
def text
assert 'not null' == text ?: 'not null'
text = 'Hi!'
assert 'Hi!' == text ?: 'not null'Avoid null pointer exception:
class Country {
Capital capital
}
class Capital {
String name
}
def switzerland = new Country()
println switzerland?.capital?.name