Groovy as "Better Java"
Join the DZone community and get the full member experience.
Join For Free
you can use groovy in different ways - for scripting, grails, quick prototyping, creation of dsls etc.
but i like groovy first of all as "better java". really, look - almost every java code is valid groovy code, i.e. - if you do not remember how to do something in a groovy way, you can write java code in a groovy class, but if you remember - use closures, groovy lists, and many other nice features
the only thing, that does not allow me to use groovy in a production code instead java - is the lack of compilation time errors in many cases - calling to non existing methods or variable, etc.
many groovy frameworks is using this (see, for example
groovy xml handling
), but if i'm writing regular code, i want to see here compilation errors.
finally, groovy 2.0 provides a feature of strict compilation time checking.
let's take such class:
let's take such class:

it passes a compilation w/o any problem.
but if we will add @typechecked (this annotation may be used for a class or a method), we will receive compilation errors:

this type checking is turned on automatically also if we are turning on static compilation for the class, using annotation @compilestatic:

so now i can use groovy for production code, instead of java!
full list of compile time messages for @typechecked you can see
here
.
Groovy (programming language)
Java (programming language)
Opinions expressed by DZone contributors are their own.
Trending
-
Testing, Monitoring, and Data Observability: What’s the Difference?
-
DevOps Pipeline and Its Essential Tools
-
You’ve Got Mail… and It’s a SPAM!
-
Developers Are Scaling Faster Than Ever: Here’s How Security Can Keep Up
Comments