groovy_reserved_words_-_groovy_keywords

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

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

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

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.

Snippet from Wikipedia: Apache Groovy

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

Groovy 1.0 was released on January 2, 2007, and Groovy 2.0 in July, 2012. Since version 2, Groovy can be compiled statically, offering type inference and performance near that of Java. Groovy 2.4 was the last major release under Pivotal Software's sponsorship which ended in March 2015. Groovy has since changed its governance structure to a Project Management Committee in the Apache Software Foundation.

Fair Use Sources

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, 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)

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# Keywords, .NET 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)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

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


groovy_reserved_words_-_groovy_keywords.txt · Last modified: 2024/04/28 03:50 (external edit)