-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Philip Ford edited this page Jan 15, 2017
·
30 revisions
- Very similar to Java, but less verbose.
- Files have
.groovyextensions - Semicolons are optional at the end of lines.
The following packages are automatically imported by Groovy, so you don't have to import them:
import java.lang.*
import java.util.*
import java.io.*
import java.net.*
import groovy.lang.*
import groovy.util.*
import java.math.BigInteger
import java.math.BigDecimalIt means that datatype or return type of a property/function/method is unspecified, and that Groovy will attempt to infer the type.
- It does declare a standalone function per se. It is a return type.
- If you use a visibility modifier, the presence of
defis unnecessary.
- Can be invoked without parentheses around the parameter list.
A more concise ternary operator: ?:
def sampleText
// Normal ternary operator.
def ternaryOutput = (sampleText != null) ? sampleText : 'Hello Groovy!'
// The Elvis operator in action. We must read: 'If sampleText is not null assign
// sampleText to elvisOuput, otherwise assign 'Viva Las Vegas!' to elvisOutput.
def elvisOutput = sampleText ?: 'Viva Las Vegas!'- Everything has
publicvisibility by default.- This means that if you omit the visibility modifier for a class/method, the visibility is
public.
- This means that if you omit the visibility modifier for a class/method, the visibility is
- To assign package (default) visibility to a class or method, you must annotate it with
@PackageScope.