Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of underscore in Groovy

Tags:

groovy

What is the meaning of an underscore in a Groovy template?

if(_.isString(document.get....))
    ....
like image 781
Stainedart Avatar asked Nov 06 '12 16:11

Stainedart


People also ask

What does underscore mean in Java?

In Java SE 7 and later, any number of underscore characters ( _ ) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.

How do you define a variable in Groovy?

Variables in Groovy can be defined in two ways − using the native syntax for the data type or the next is by using the def keyword. For variable definitions it is mandatory to either provide a type name explicitly or to use "def" in replacement. This is required by the Groovy parser.

How do I know the type of variable in Groovy?

You can use the getClass() method to determine the class of an object. Also, if you want to check if an object implements an Interface or Class, you can use the instanceof keyword. That's it about checking the datatype of an object in Groovy.

Is underscore allowed in Java?

Using underscore in a variable like first_name is still valid. But using _ alone as a variable name is no more valid. Even if you are using earlier versions of Java, using only underscore as a variable name is just a plain bad style of programming and must be avoided.


1 Answers

_ is a valid identifier in Groovy (and Java)

Ie: this:

def _ = 13
println _

Prints 13. You'll have to give a bit more context to find out what is setting _ in your given situation

like image 149
tim_yates Avatar answered Oct 29 '22 08:10

tim_yates