We say Java project development based on groovy language is an agile development, and the groovy language itself offers a lot of agility in addition to using grails as a Web development platform.
We know that in the Java language, we use the Equals method to determine whether the values of two strings are equal, and "= =" as symbols that determine whether two object references are the same. It turns out that we use the Equals method more than the "= =" notation, especially in the use of strings.
In the actual coding process, the shape is as follows:
if(abc1.equals(abc2))
{
……
}
Such an If language is particularly numerous, but each time we have to spell the Equals method, instead of simply using the "= =" symbol. While Ides such as Eclipse can help us spell the Equals method, the use of the Equals method delays our time, far from using the "= =" Symbol for agility.
The groovy language takes into account our actual requirements and decisively uses the "= =" notation instead of the Equals method to provide the agility of groovy language programming.
def abc1 = 'abc'
def abc2 = "abc"
println abc1 == abc2
The result printed is true.
In this way, we do not have to abc1.equals the IF (ABC2), but can use directly:
if(abc1==abc2)
{
……
}
Is it convenient for many?
You can even use the "= =" symbol to determine whether the contents of a collection two objects are the same, such as:
def list1 = [1]
def list2 = [1]
println list1 == list2
You can run the above statement to see that the result is true.
The contents of the two Map objects are the same or can be judged by the "= =" notation, such as:
def map1 = ['name':'tom']
def map2 = ['name':'tom']
println map1 == map2
The result is true. But you have to run the following statement:
def map1 = ['name':'tom']
def map3 = ['name':'alice']
println map1 == map3