Things to remember

Strings

  • Strings are not Lists. In the JVM java.lang.String does not implement java.util.List.
  • Arrays are not Lists. In the JVM arrays and java.util.List are quite different. In Groovy we support both as different types to ensure we interoperate cleanly with Java code. Though we try wherever possible to make them interchangable and appear polymorphic.

Maps

  • Maps override the dot operator, so myMap.size will return null unless you have a value for map[size]. Use map.size() or map.@size instead.
  • In map literals, all keys are interpreted as strings by default! If you want to use a variable or other literal as a key, use parentheses like so: myMap = [(var1):val, (var2):val]
  • See the Maps user guide

Labels

 
(None)
  1. Aug 08, 2004

    B. K. Oxley (binkley) says:

    But the JDK5 Iterable interface helps alleviate the pain somewhat as you can use...

    But the JDK5 Iterable interface helps alleviate the pain somewhat as you can use both in a foreach construct.

  2. Nov 09, 2005

    James Strachan says:

    Sure, but that is only for the foreach construct. In groovy we can do various c...

    Sure, but that is only for the foreach construct.

    In groovy we can do various closure operations on lists and arrays..

    customers.each { print it }
    customers.findAll { it.country == "UK" }.each { println it }

    etc