Java Reference
In-Depth Information
Other than the normal Groovy simplifications (omitting the word public , lack of semi-
colons, use of writer rather than getWriter() , and the optional parentheses on
print ), this isn't much different from a Java implementation. Use Groovy if you prefer
the slightly shorter code, but really the choice of language is a matter of style.
What Groovy does provide is a category class to simplify the code even further. Category
classes are an example of Groovy's metaprogramming capabilities. They show how to add
methods to existing classes in a specified block of code, unlike using the metaclass ob-
ject to add them everywhere in your program. If you ever wanted to understand categories,
ServletCategory is a great, extremely simple, useful example.
Categories
Use a Groovy category to add methods to existing classes when you only need those meth-
ods under specific circumstances. Category methods are only available in a use block.
Figure 10.2 shows a sample of the GroovyDocs for the groovy.servlet.Servlet-
Category class.
Search WWH ::




Custom Search