Groovy 2 update

Greach, Madrid, Spain

Cédric Champeau, SpringSource

Jan 2013 25th

About me

Past : Groovy contributor

Present: Core Groovy committer

Follow me

Before we start...

A little surprise...

About Groovy

Groovy 2

Modularity

Modularity

The new JARs

Extension modules

Extension modules

Extension module descriptor

Groovy 2

JDK 7 enhancements

JDK 7 enhancements: Binary literals

JDK 7 enhancements: Underscores in literals

JDK 7 enhancements: Multicatch

Groovy 2

InvokeDynamic support

InvokeDynamic

Groovy 2

Static type checking

Static type checking

Goal

Turn the compiler grumpy

Static type checking: typos

Type checking options

if set on a class, type checks:

if set on a method, type checks:

You can prevent some code from beeing type checked:

Static type checking: assignments

Static type checking: return types

Static type checking: type inference

Static type checking: mixing static and dynamic

Static type checking: instanceof

Static type checking: lowest upper bound

Represents a "common super type" that may not exist as a real class/interface

List<Comparable & Serializable>

Static type checking: flow typing

Static type checking shouldn’t complain even for bad coding practicies which work without type checks

STC gotchas: dynamic vs static

STC gotchas: closure argument types

STC gotchas: closure shared variables 1/2

STC gotchas: closure shared variables 2/2

Groovy 2

Static compilation

Static compilation

Only change required: @TypeChecked to @CompileStatic

Static compilation: pros

You gain

Static compilation: cons

But you loose

Groovy 2.1

Full InvokeDynamic support

Groovy 2.1

@DelegatesTo

@DelegatesTo

Enters @DelegatesTo!

@DelegatesTo

Define a class that has a foo() method

Define a with method that does a "reversed with"

Use it

Will IDE know about foo()? Would the type checker know?

@DelegatesTo

@DelegatesTo

@DelegatesTo: advantages

Groovy 2.1

@Alias

Alias annotations

Alias annotations

The verbose declaration

Define an alias

Use it!

Alias annotations

As an example, Groovy 2.1 includes @CompileDynamic as an alias for @CompileStatic(TypeCheckingMode.SKIP)

Groovy 2.1

Compilation configuration

Taking control of your Groovy

Compilation configuration script

The configuration script gives you access to CompilerConfiguration

The CompilationCustomizerBuilder is available outside of this context

Groovy 2.1

Type checking extensions

Type checking extensions

Extensive description tomorrow, "Type checking your DSLs" at 10:15

Type checking extensions: example

Take this code

Type checking extensions

Questions

Thank you!

/

#