Let's learn about the Groovy language

Groovy is an agile dynamic language for the Java virtual machine. As a mature object-oriented programming language, it can be used not only for object-oriented programming, but also as a pure scripting language. The Groovy language provides programmers with the ability to write simple programs and make full use of existing Java code.

It is built on the powerful Java language and adds many features from languages ​​such as Python, Ruby and Smalltalk, such as dynamic type conversion, closures, and meta-programming support. Not only that, but closely linked to Java JAR files, Groovy's code runs like a dynamically typed scripting language, which can fully access the data of static type Java objects.

Groovy installation

Download GDKGDK, configure the installation environment, that is, the environment variables, and the type of java (it seems that you don’t need to run AS directly), and then develop Groovy in Android Studio. When you run it for the first time, you need to configure the path of lib, and select groovy according to the prompts. Set into the lib directory under the installation directory. That's it.

The basic rules of Groovy:

As a dynamic language, all variables in Groovy are objects. When declaring a variable, it is not mandatory to declare the type, but you need to use the def keyword before the variable.

Properties are private by default, get and set methods are provided by default, and classes are public by default.

";" is not needed at the end of the statement to indicate the end of the statement

The file name ends with .groovy

Annotation, his annotation is the same as java, support

Variable names start with a letter, dollar sign $, or underscore _, and cannot start with a string

Groovy reserved words

Video Processors

Guangzhou Chengwen Photoelectric Technology co.,ltd , https://www.cwstagelight.com

Posted on