gr8vyguy@Blogjava

          Groovy讀書筆記3

          Chapter 04 The collective Groovy datatypes

          Groovy support collection types: ranges, lists and maps.

          how and what

              language expressiveness, 語言的表達能力
                    how much does the code say what, instead of how.


          Range

             1..10       from 1 to 10
             1..<10    from 1 to 9

             10..1     reverse range
           
             the range elements must implement ++, -- and <=>.

             for in range loop

             index -1 means last element.

          Groovy的Command還是要少用,加上括號吧

          List

               java.util.List

               list = new LinkedList()
               list[0] = 1

              an array from Java to Groovy => converted to a list

              toList()  method, convert a collection to a list

             The list’s getAt() and putAt() are overloaded with the parameters: integer, integers, range, 

             list[0..2] returns a sublist, not a new list, changing in the sublist, change the original list.

             list.inject(initial) { accumulator, index -> f(accumulator, index) }

          duck typing
              as long as something walks like a duck and talks like a duck, 
              we happily treat it as a duck.

          Map

              java.util.Map

             access map
                1. subscript operator map[key], getAt()
                2. dot operator .
                3. method get(), default value

          ConcurrentModificationException

              structurelly changing while iterating, such as list.each

          Copy Semantics and Modify Semantics

              works on a copy of the collection, collect, find, grep
              works in place, e.g. add()

          posted on 2007-12-13 01:26 gr8vyguy 閱讀(520) 評論(0)  編輯  收藏 所屬分類: Java

          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統(tǒng)計

          公告

        1. 轉載請注明出處.
        2. msn: gr8vyguy at live.com
        3. 常用鏈接

          留言簿(9)

          隨筆分類(68)

          隨筆檔案(80)

          文章分類(1)

          My Open Source Projects

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 旌德县| 达日县| 肥西县| 西充县| 宜城市| 弥渡县| 唐山市| 福海县| 宾川县| 崇左市| 民县| 东平县| 崇义县| 民和| 延长县| 鹤庆县| 镇平县| 永康市| 甘德县| 石台县| 敦化市| 左贡县| 安远县| 拜城县| 益阳市| 拉萨市| 大名县| 即墨市| 陆河县| 塔城市| 天津市| 肥西县| 汶上县| 五河县| 平度市| 东港市| 土默特右旗| 于都县| 望江县| 南汇区| 常熟市|