W3cubDocs

/Groovy 3.0

[Java] Annotation Type CompileStatic

  • groovy.transform.CompileStatic
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({   ElementType.METHOD,         ElementType.TYPE,
            ElementType.CONSTRUCTOR
})
@GroovyASTTransformationClass("org.codehaus.groovy.transform.sc.StaticCompileTransformation")
public @interface CompileStatic

This will let the Groovy compiler use compile time checks in the style of Java then perform static compilation, thus bypassing the Groovy meta object protocol.

When a class is annotated, all methods, properties, files, inner classes, etc. of the annotated class will be type checked. When a method is annotated, static compilation applies only to items (closures and anonymous inner classes) within the method.

By using TypeCheckingMode.SKIP, static compilation can be skipped on an element within a class or method otherwise marked with CompileStatic. For example a class can be annotated with CompileStatic, and a method within can be marked to skip static checking to use dynamic language features.

See Also:
CompileDynamic

Element Summary

Optional Element Summary
Type Name and Description
String[] extensions
The list of (classpath resources) paths to type checking DSL scripts, also known as type checking extensions.
TypeCheckingMode value
Default:
TypeCheckingMode.PASS

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Element Detail

public String[] extensions

The list of (classpath resources) paths to type checking DSL scripts, also known as type checking extensions.

Returns:
an array of paths to groovy scripts that must be on compile classpath
Default:
{}

public TypeCheckingMode value

Default:
TypeCheckingMode.PASS

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/3.0.7/html/gapi/groovy/transform/CompileStatic.html