Java Reference
In-Depth Information
10 Paul King, one of the coauthors of Groovy in Action (Manning, 2007) and a fantastic developer. Let me be blunt
about this: everything Paul King writes is good. He tends to add his presentations to SlideShare.net as well, so go
read them as soon as humanly possible.
ImmutablePoint p = ImmutablePointFactory.instance.newImmutablePoint(3,4)
That works just fine. It's when I try to do the same thing in Java that I run into problems.
Again, the compiler understands, but I've never been able to coax my IDE into believing
that the factory class has a public static field called instance in it.
Still, the annotation works and the IDEs will eventually understand how to deal with it.
In fact, all the cool new AST transformations work, and I encourage you to consider them
significant shortcuts to writing applications.
There are other AST transformations available and more being written all the time. I en-
courage you to keep an eye on them in case one comes along that can simplify your code
the same way the ones just discussed do.
As cool as AST transformations are, though, our last task is so much easier to do in Groovy
than in Java that it practically sells Groovy to Java developers all by itself. That issue is
parsing and generating XML.
4.5. Working with XML
Way back in the late 90s, when XML was young, new, and still popular (as hard to imagine
as that may be now), the combination of XML and Java was expected to be a very product-
ive one. Java was the portable language (write once, run anywhere, right?), and XML was
the portable data format. Unfortunately, if you've ever tried working with XML through
the Java built-in APIs you know the results have fallen far short of the promise. Why are
the Java APIs for working with XML so painful to use?
Here's a trivial example. I have a list of topics in XML format, as shown here:
<books>
<book isbn="...">
<title>Groovy in Action</title>
<author>Dierk Koenig</author>
<author>Paul King</author>
 
Search WWH ::




Custom Search