How so? I don't think there are many good things to say about Groovy, but I generally agree with most new features introduced to Java. What do you think Groovy does better?
Oops, sorry those are features java "stole" from groovy.
Java has the nullsafe operator now and the elvis too, doesn't it?
I don't use the spaceship operator much, implicit sorting works pretty well.
Groovy's closures have a lot less GOTCHAs. They simply work as expected, at least to me. Half the time I use java closures and I get complaints in compilation that I don't get in Groovy, but maybe they've improved closures more.
Groovy's GPars library is the bomb for concurrency/parallelism. I don't know if I could function in normal java constructs.
The .with keyword is a sneaky useful technique where you can declare a piece of data like:
It allows chained calls that flow naturally. Groovy generally allows pretty compact flowed calls which makes scripts a lot easier.
Groovy scripting with implicit vars is a lot easier than any java scripting, even with the "simplification" described.
The shorthand access/navigation of nested lists and maps, and the map / list literals (also taken by java at some point I think) are really nice to have. Also a + operator for lists and maps I use a lot
Groovy's ability to generically call methods without mucking through 10 lines of reflection is sometimes nice.
The auto-gen of getter/setters is a must have, I think Kotlin has those too?
CompileStatic lets me selectively use full java speed without groovy overhead.
In general, I like Groovy because it is typing-optional. Python and Javascript suck because they don't really have optional type enforcement. Java sometimes asks for too much typing. Groovy lets me select as needed.
The actual sane = for string assignment and == for sane string comparison is nice.
But honestly, Java with the listed features is a lot better. I'll probably still use groovy for doing what would normally done with bash (UGH) since I have a big CLI/scripting library base that handles argument parsing, json, encode/decode, encrypt/decrypt, zip/unzip, in nice compact syntax.
Groovy is basically a dead language now anyway. The world is overrun by JavaScript and Python, and AI looms to replace us all with horrid AI python or javascript glue code.
You can be really productive, expressive and performant in Groovy. So much of the language still works well with @CompileStatic and doesn’t require dynamic typing. Writing clear code that has decent refactoring support in IntelliJ.
Don’t forget traits! When are we getting traits in Java? Probably never.
Optional semicolons and parentheses to cut the line noise and enable internal DSLs.
Though Java has improved implicit typing with `var` and now we have reasonable lambdas, Java is still not a high-level language, but maybe it is now medium-high.
> Oops, sorry those are features java "stole" from groovy.
Well, yeah? Java's explicit strategy for the last few decades is to let other languages experiment, then implement the ideas that worked out once the dust has settled.
- triple-quote strings / blocks
- minimal class boilerplate (this posting)
- closures (Java closures are worse IMO)
- usable hashbang for UNIX
- I think java has strings in switch now, don't they? Do they have expressions?
WAIT, does Java STILL force you to write getter/setters?