Updating xint program
, etc, are valid, but expressions that would contain parentheses like method calls, curly braces for closures, or arithmetic operators would be invalid.Given the following variable definition of a number: def number = 1 (1) def eager GString = "value == $" def lazy GString = "value == $" assert eager GString == "value == 1" (2) assert lazy GString == "value == 1" (3) number = 2 (4) assert eager GString == "value == 1" (5) assert lazy GString == "value == 2" (6)String take String(String message) def message = "The message is $" (1) assert message instanceof GString (2) def result = take String(message) (3) assert result instanceof String assert result == 'The message is hello' Although interpolated strings can be used in lieu of plain Java strings, they differ with strings in a particular way: their hash Codes are different.Linked Hash Map Here, we used numbers as keys, as numbers can unambiguously be recognized as numbers, so Groovy will not create a string key like in our previous examples.
Linked List Linked List other Linked = [3, 4, 5] (2) assert other Linked instanceof
Plain Java strings are immutable, whereas the resulting String representation of a GString can vary, depending on its interpolated values.
Even for the same resulting string, GStrings and Strings don’t have the same hash Code.
This is mandatory if your key string isn’t a valid identifier, for example if you wanted to create a string key containing a hash like in: ["street-name": "Main street"].
Groovy supports the usual familiar arithmetic operators you find in mathematics and in other programming languages like Java.