DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

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
  1. DZone
  2. Coding
  3. Languages
  4. Groovy as "Better Java"

Groovy as "Better Java"

Pavel Bernshtam user avatar by
Pavel Bernshtam
·
Jun. 08, 12 · News
Like (0)
Save
Tweet
Share
17.24K Views

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:




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

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: