This chapter covers
- Groovy’s approach to typing
- Operators as method implementations
- Strings, regular expressions, and numbers
Do not worry about your difficulties in mathematics. I can assure you mine are still greater.
Groovy supports a limited set of datatypes at the language level; that is, it offers constructs for literal declarations and specialized operators. This set contains the simple datatypes for strings, regular expressions, and numbers, as well as the collective datatypes for ranges, lists, and maps. This chapter covers simple datatypes; the next chapter introduces collective datatypes.
Before we go into details, we’ll talk about Groovy’s general approach to typing. With this in mind, you can appreciate Groovy’s approach of treating everything as an object and all operators as method calls. You’ll see how this improves the level of object orientation in the language compared to Java’s division between primitive types and reference types.
We then describe the natively supported datatypes individually. By the end of this chapter, you’ll be able to confidently work with Groovy’s simple datatypes and have a whole new understanding of what happens when you write 1+1.