Using Java classes from Groovy
The Groovy language is designed in a way that it fully supports the Java syntax (there are only few minor exceptions; for example, do..while
is not supported in Groovy). Most of the code that you can write in Java can automatically be considered Groovy code as well.
In this recipe, we will learn how simple it is to use existing Java classes and libraries from your Groovy code and we will explore some basic language features that makes Groovy—groovy!
How to do it...
This recipe has a rather simple setup. You can either start up the groovyConsole
, as described in the Starting groovyConsole to execute Groovy snippets recipe in Chapter 1, Getting Started with Groovy, or you can create a new file with the *.groovy
extension. ...
Get Groovy 2 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.