The groovy language has a lot of seemingly obscure gadgets, but after use, we often marvel at its enormous energy, and gstring is one of them.
The Java string object is our most common object, but it is also the most criticized object. In a word, string is very inconvenient to use. Gstring is not only easy to use, but also the basis of the dynamic nature of
Gstring
In addition to using gchar * for string processing, g l I B also defines a new data type: g s t r I n g. It is similar to the string type of standard C, but g s t r I n gcan automatically increase. Its string data ends with n u L. These features can prevent
Program Buffer overflow. This is a very important feature. The following is the definition of g s t r I n g:
Struct gstring
{
Gchar * STR;/* po
of nullpointerexception, but it cannot be abused.
[Java] view plaincopy
Def result = OBJ ?. Property
In the code, obj is an object, and property is a familiar object. In this line of code, if obj is not null, the value of the property is returned. If obj is null, this will directly return null. Statements can be serialized all the time.
[Java] view plaincopy
Def result = ?. B ?. C ?. D...
4. Field operations
According to the standard of groovy
to it, which is of the String type, and assign an Integer to it, which is converted to an Integer.
6. Loop
Delete the entire source file and use the following code instead:
Def var = "hello" +
"World" +
", Groovy! "
Def repeat (val ){
For (I = 0; I
Println val
}
}
Repeat (var)
Output:
Hello world, groovy!
Hello world, groovy!
Hello world,
1, first download a groovy SDK, download the address point I; 2, unzip the groovy SDK that you downloaded; Remember this decompression address and use it later; 3, create a new groovy project with Idea 4, project structure as shown 5, because we want to download the jar package, we are here with Maven management, create a new Pom.xml file, the code in the f
The same points in groovy and Java are:6+, 4+, 8+, 12+, 13, 14, 15, +, 20+, 21, 22, 23, 28+, 29+,, and 31+, 32+ + means groovy not only covers the syntax of Java, but it also has an enhanced section. The different points of groovy and Java are:0, 1, 2, 5, 7, 9, 11, 16, 17, 19, 24, 25, 26, 27 The sequence numbers listed below are in order: 0. In
Turn from: Groovy easy to get started-get a quick grasp of groovy with Java comparison (updated on 2008.10.18)in the previous articles, I've already told you what groovy is, how important it is to learn groovy, and what I don't know about groovy as a friend of my blog.Groovy
Use groovy to think about Chapter 3 Groovy Development Environment
Author: chszs, reprinted with note. Blog homepage: http://blog.csdn.net/chszs
This chapter will continue with the groovy language. First, we will learn about groovy scripts, including compiling and running groov
code.
Package Io.swagger.script
/**
* Test
* @author Fulei.yang */
class Test {public
static void Main (string[] args) {
println (' Hello World ')
}
}
Well, let's explore the information from this most basic example, and we can get some of the following information:
1, groovy can also like Java has a strict class structure, of course, you only write a line of println in the groovy file
}
List.each {println It}
Usually we recommend using the third style above, which is more natural because it is superfluous to have no parentheses!
But groovy does not allow you to remove parentheses in certain situations. As I said before, the top-level expression can be omitted, but the nested method or the right side of the assignment expression, you cannot omit:
def foo (n) {n}
println foo1//error notation
def m = foo1
Groovy Discovery: Writing groovy-style code for strings
Groovy Explore custom range three custom range and responsibility chain mode
Groovy Explore custom Range two custom range class with decorate mode (next)
Groovy Explore custom Range two custom range class and decor
It has been said before that many people choose groovy because of their low learning costs, as long as you have the basics of Java and learn quite quickly. In contrast, Scala (another JVM dynamic language) syntax is more difficult to learn (though not yet learned, but online reviews are).As a Java programmer, I'm going to get myself groovy.From JDK to GDK1. As the core of Java development, JDK is the part that all Java programmers need to learn and us
Let's look at an example of a Java regular expression.Import Java.util.regex.matcher;import Java.util.regex.pattern;public class Testmatch {public static void main ( String[] (args) { pattern pattern = pattern.compile ("g.*"); Matcher Matcher = Pattern.matcher ("Groovy"); System.out.println (Matcher.matches ());} }In fact, this code means that groovy is not a match for regular
Introduction: Groovy's concise syntax frees developers from the typical Java™ architecture that requires code compilation but does not help express what the program really wants to achieve. In this revival of the Groovy series, groovy developer and special columnist J. Scott Hickey takes you through a series of comparisons between regular Java code and Groovy Cod
Object-oriented in Groovy and Groovy object-oriented
As mentioned above, groovy supports scripts and classes. The previous section briefly describes the relationship between scripts and classes. This section mainly introduces the knowledge of classes in groovy, that is, object-oriented knowledge.1. Type 1.1 Original Ty
: [Java] view plain copy def result = a?: bIf the condition is true, that is, a is true or a has a value, the result is a, otherwise the result is B 3. Security Placeholder
This is useful to avoid a lot of nullpointerexception, but you can't abuse [Java] view plain copy def result = obj?. PropertyIn the code, obj is an object, the property is a familiar object, the meaning of this line of code, if obj is not NULL, it will return the value of the properties attribute, if obj is null, this will di
Groovy supports two types of strings: A generic Java string, an instance of java.lang.String, and Gstrings, which is an instance of groovy.lang.GString, and allows the text to contain placeholders. Gstrings is not a subclass of string because the string class is the final class (final Class) that cannot be inherited. However, Gstring is the same as a generic string, because
Groovy classes are compiled into bytecode of Java, that is, there is a one-to-one ing between groovy classes and Java classes. Every groovy class can be stored in JavaCodeBecause the groovy class is also a Java class.
Usage of groovy list:
Def list = [1, 2, 'Hello', n
Three-day Dragon Boat Festival holiday, I learned jruby and groovy. At last I thought groovy was easy to use. Using groovy is a bit like writing basic, and there are no more rules like Java. During development, code is used to describe the execution logic, rather than writing a large number of classes that comply with Java "patterns" to implement certain logic fu
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.