Chapter 10. Groovy as a static language

 

This chapter covers

  • Incorporating static typing in a dynamic language
  • Using the @TypeChecked annotation
  • Type inference and flow typing
  • Static compilation and the @CompileStatic annotation
  • Type checking extensions

We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.

T. S. Eliot

There are endless debates in computer programming. vi or emacs? Tabs or spaces? Interfaces or abstract classes? Likewise, the debate over the benefits of static versus dynamic languages is never ending. You’ll find people telling you that static languages are the best because you can find errors at compile time, while on the other side, people will empathize how powerful and concise dynamic code can be. In most languages, you have to choose one or the other. Not so in Groovy.

Groovy gives you the best of both worlds: it’s dynamic, yet able to apply type checks just like static languages. It can optionally provide the runtime characteristics of a static language. It’s your choice.

10.1. Motivation for optional static typing

 
 

10.2. Using @TypeChecked

 
 
 

10.3. Flow typing

 
 
 
 

10.4. Static compilation

 
 
 

10.5. Static type checking extensions

 
 
 

10.6. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest