Groovy Reserved Words - Groovy Keywords (CloudMonk.io)

Groovy Reserved words - Groovy keywords



Return to Groovy

Also called: Groovy Language Keywords, Groovy Reserved Keywords, Groovy Keywords, Groovy Reserved Identifiers, Groovy Reserved words


https://groovy-lang.org/syntax.html#_keywords



Groovy has the following reserved keywords:

Table 1.

Reserved Keywords

* abstract
* assert
* break
* case
* catch
* class
* const
* continue
* def
* default
* do
* else
* enum
* extends
* final
* finally
* for
* goto
* if
* implements
* import
* instanceof
* interface
* native
* new
* null
* non-sealed
* package
* public
* protected
* private
* return
* static
* strictfp
* super
* switch
* synchronized
* this
* threadsafe
* throw
* throws
* transient
* try
* while


Of these, Groovy const, Groovy goto, Groovy strictfp, and Groovy threadsafe are not currently in use.

The reserved keywords can’t in general be used for Groovy variable, Groovy field and Groovy method names.

A trick allows methods to be defined having the same name as a keyword by surrounding the name in quotes as shown in the following example:

// reserved keywords can be used for method names if quoted

def "abstract"() { true }

// when calling such methods, the name must be qualified using "this."

this.abstract()

Using such names might be confusing and is often best to avoid. The trick is primarily intended to enable certain Java integration scenarios and certain DSL scenarios where having "verbs" and "nouns" with the same name as keywords may be desirable.

In addition, Groovy has the following contextual keywords:

Table 2. Contextual Keywords

* as
* in
* permits
* record
* sealed
* trait
* var
* yields


These words are only keywords in certain contexts and can be more freely used in some places, in particular for variables, fields and method names.

This extra lenience allows using method or variable names that were not keywords in earlier versions of Groovy or are not keywords in Java. Examples are shown here:

// contextual keywords can be used for field and variable names
def as = true
assert as

// contextual keywords can be used for method names
def in() { true }
// when calling such methods, the name only needs to be qualified using "this." in scenarios which would be ambiguous
this.in()
Groovy programmers familiar with these contextual keywords may still wish to avoid using those names unless there is a good reason to use such a name.

The restrictions on reserved keywords also apply for the primitive types, the boolean literals and the null literal (all of which are discussed later):

Table 3. Other reserved words

* null
* true
* false
* boolean
* char
* byte
* short
* int
* long
* float
* double

While not recommended, the same trick as for reserved keywords can be used:

def "null"() { true } // not recommended; potentially confusing

assert this.null() // must be qualified

Using such words as method names is potentially confusing and is often best to avoid, however, it might be useful for certain kinds of DSLs.


Error: File not found: wp>Groovy (programming language)

Fair Use Sources


Fair Use Sources:
* https://groovy-lang.org/syntax.html#_keywords
* ddg>Groovy keywords on DuckDuckGo


Groovy: Groovy Fundamentals, Groovy Inventor - Groovy Language Designer: James Strachan in August 2003; Maven-Gradle, JVM, Groovy keywords, Groovy data structures - Groovy algorithms, Groovy syntax, Groovy OOP, Groovy installation, Groovy containerization, Groovy configuration, Groovy compiler, Groovy IDEs, Groovy development tools, Groovy DevOps - Groovy SRE, Groovy data science - Groovy DataOps, Groovy machine learning, Groovy deep learning, Functional Groovy, Groovy concurrency, Groovy history, Groovy bibliography, Groovy Glossary - Glossaire de Groovy - French, Groovy topics, Groovy courses, Groovy Standard Library, Groovy libraries, Groovy frameworks, Groovy research, Groovy GitHub, Written in Groovy, Groovy popularity, Groovy Awesome list. (navbar_groovy - see also navbar_jvm, navbar_gradle)



Reserved Keywords: (Also called: Language Keywords, Reserved Keyword, Reserved Word, Keywords, Reserved Identifier, Reserved Identifiers) Ada Keywords, ALGOL 68 Keywords, Angular Keywords, Android Keywords, Apple iOS Keywords, ARM Assembly Keywords, Assembly Keywords, AWK Keywords, Bash Keywords, BASIC Keywords, C Keywords (https://en.cppreference.com/w/c/keyword), C Sharp Keywords | C# Keywords, dot NET Keywords | .NET Keywords, C plus plus Keywords | C++ Keywords (https://en.cppreference.com/w/cpp/keyword), Clojure Keywords, COBOL Keywords, Dart Keywords, Delphi Keywords, Django Keywords, Elixir Keywords, Erlang Keywords, F Sharp Keywords, Fortran Keywords, Flask Keywords, Golang Keywords, Groovy Keywords, Haskell Keywords, Jakarta EE Keywords, Java Keywords, JavaScript Keywords, JCL Keywords, Julia Keywords, Kotlin Keywords, Lisp Keywords (Common Lisp Keywords), Lua Keywords, MATHLAB Keywords, Objective-C Keywords, OCaml‎ Keywords, Pascal Keywords, Perl Keywords, PHP Keywords, PL/I Keywords, PowerShell Keywords, Python Keywords, Quarkus Keywords, R Language Keywords, React.js Keywords, Rexx Keywords, RPG Keywords, Ruby Keywords, Rust Keywords, Scala Keywords, Spring Keywords, SQL Keywords, Swift Keywords, Transact-SQL Keywords, TypeScript Keywords, Visual Basic Keywords, Vue.js Keywords, X86 Assembly Keywords, X86-64 Assembly Keywords. (navbar_reserved_keywords - see also navbar_cpp_keywords)




----



Cloud Monk is Retired (impermanence |for now). Buddha with you. Copyright | © Beginningless Time - Present Moment - Three Times: The Buddhas or Fair Use. Disclaimers



SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.



----