Skip to content

Commit

Permalink
#33: Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jaccomoc committed Jul 17, 2024
1 parent 52c3b35 commit 7106392
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/pages/language-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,35 @@ class Y extends X {
def y = new Y(i:4, field:'value1', anotherField:'value2')
y.method() // returns 'Y: value1:value2:4'
```

## Packages and Import Statements

Classes can be grouped into packages (libraries) just like in Java/Groovy using
a package statement:

```groovy
package org.customer.utils
class Useful {
static def func() {
...
}
}
```

Import statements allow you to use a class without needing to fully qualify
it with its package name each time:
```groovy
import org.customer.utils.Useful
def x = Useful.func()
```
Import allows you to give a class an alias using `as`:
```groovy
import org.customer.utils.Useful as U
def x = U.func()
```
You can also import static functions and class constants using `import static`:
```groovy
import static org.customer.utils.Useful.func as f
def x = f() // invokes Useful.func()
```

0 comments on commit 7106392

Please sign in to comment.