Message-ID: <1576562560.25529.1412108440038.JavaMail.firstname.lastname@example.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_25528_1772052108.1412108440038" ------=_Part_25528_1772052108.1412108440038 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Groovy's static import capability allows you to referen= ce imported classes as if they were static methods in your own class. This = is similar to Java's static import capability but works with Java = 1.4 and above and is a little more dynamic than Java in that it allows you = to define methods with the same name as an imported method as long as you h= ave different types. If you have the same types, the imported class takes p= recedence. Here is a sample of its usage:
The first static import illustrates defining
LIGHT_GRAY as =
if it was defined locally as a static field.
The next two examples sh= ow renaming (called aliasing) of a field and a method respectively= .
The final example illustrates wild-carding for fields and methods a= nd also selecting between the locally defined
toHexString and =
toHexString based on parameter matching.
As another example, here is how to statically import some of the Math fu= nctions:
Note: Groovy does not check beyond your impo= rt class if what you statically import exists. If you import a nonexisting = method, field or property Groovy will not fail at compile time, but later w= hen executing the compiled code.
Java language guide recommends to use static imports very sparingly beca= use they can harm readability when overused.