<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    gr8vyguy@Blogjava

    Groovy讀書筆記4

    Closure

    Use Cases for Closures
       
        separating iteration logic from what to do on each iteration

        handling resources, 
            open
            do the job   // in a closure, as parameter
            close

    Implicit Variable of Closure
        
        it                     default parameter

        this                enclosing class
        owner           enclosing object, class or closure
        delegate       same as owner, but changeable 

    closure without parameters
       { -> ... }

    closure with one parameter
       { ... }, { x -> ... }

    Scope of a closure

       a closure must remember original context frame. it is closed under declaration context.

    Return from a closure or method
      
      end return
          the value of  last expression is returned.

      prematurely return with return keyword

    Groovy Control Structure

    Groovy Truth

       Boolean Test: evaluate an expression to be true or false
       
       any non-void type can be evaluated as Boolean.
            to be true
                  non empty, non zero, non null

    Typo, forget a =
      
       if(x = 1) is not allowed in groovy.

      if(1 == x) is safe than if(x == 1)

    Loop
      an object can be iterable.

    assert
      
      如果沒有assert, code一樣產(chǎn)生夠用的錯誤信息,那么就不需要assert

      assert can clarify the code intents. runnable comment!

    Return Value

      method with void do not return a value
      closure always return a value, null if no value

    OO in Groovy

    dynamic, object oriented and scripting

    classes and scripts definition

    script’s binding 
        undeclared variable

        transfer variables between Script and Calller

    default visibility of fields ==> property definition

    default visibility of methods ==> public

    Reference a field

        Class and Map has some similiarity.

        obj.field
        obj[’field’]

        override get and set methods

    Parameter Type
       
      optional, if not specified, then means Object.

    Groovy’s method dispatch
       GroovyObject.invokeMethod(name, params[])

    Safe dereferencing with ?. operator

        protected from NPE

        null?.foo()   no foo called, return null

    Constructor

        called by 
            1. new ClassName(...)
            2. as with list
            3. implicit coercion with list, implicit construction

        named parameters for default constructor
            available if no constructor is defined

    Type aliasing

           import ... as ..

    Typing

         Interface

         Design by Contract

         Duck Typing, Dynamic Typing, checked by tests

    Multimethods

        method look up take the dynamic type of arguments into account.

        method dispatch at run time(Groovy) or compile time(Java)

    GroovyBeans

        obj.property mapped to obj.getProperty() or obj.setProperty(value) method

    dot-@ operator

        obj.@field access directly the field

    event in groovy bean

       btn.actionPerformed = { ... }

       groovy通過bean introspection確定是否為添加一個Listener,如果是, 生成一個ClosureListener,
       a proxy implementation of the required listener interface,調(diào)用后面的closure,添加

    GPath

          objs.p1,p2*.p3

    Spread Operator *

         *list 打散

    mix-in with use

        dynamic 增加method

        use(category) {
              ....
        }

       category中定義static methods, use后, method的第一個argument的類得到一個新的method

    Groovy's Meta-Object Protocoll(MOP)

    how Groovy performs its magic?
          interception points

    All classes programmed in Groovy are constructed by the GroovyClassGenerator, such that it implements GroovyObject interface.

    Method Dispatching

         this.invokeMethod()
         getMetaClass().invokeMethod()
         MetaClassRegistry.getMetaClass(this.class).invokeMethod()

    Usability

        intercept
        relay
        pretend


    posted on 2007-12-20 07:48 gr8vyguy 閱讀(832) 評論(0)  編輯  收藏 所屬分類: Java

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

    導(dǎo)航

    統(tǒng)計

    公告

  • 轉(zhuǎn)載請注明出處.
  • msn: gr8vyguy at live.com
  • 常用鏈接

    留言簿(9)

    隨筆分類(68)

    隨筆檔案(80)

    文章分類(1)

    My Open Source Projects

    搜索

    積分與排名

    最新評論

    主站蜘蛛池模板: 亚洲第一黄片大全| 亚洲91av视频| 七色永久性tv网站免费看| 亚洲精品自产拍在线观看动漫| 四虎永久在线观看免费网站网址| 蜜臀亚洲AV无码精品国产午夜.| 亚洲欧洲日产国码av系列天堂| 久久国产免费福利永久| 污污视频网站免费观看| 久久丫精品国产亚洲av| 免费看美女让人桶尿口| 鲁丝片一区二区三区免费| 波多野结衣亚洲一级| 久久久久国产成人精品亚洲午夜 | 免费很黄无遮挡的视频毛片| 久久精品国产亚洲AV网站| 狠狠久久永久免费观看| 久久综合九色综合97免费下载| 亚洲高清毛片一区二区| 亚洲an天堂an在线观看| 亚洲一本大道无码av天堂| 久久免费看黄a级毛片| 成全视成人免费观看在线看| 91丁香亚洲综合社区| 亚洲成AV人片在线观看无码| 国产成人免费福利网站| 91九色视频无限观看免费| 精品97国产免费人成视频| 亚洲精品伦理熟女国产一区二区| 亚洲综合在线视频| 久久精品国产亚洲Aⅴ蜜臀色欲| 色www永久免费视频| 免费h片在线观看网址最新| 三级黄色免费观看| 疯狂做受xxxx高潮视频免费| 亚洲一区精彩视频| 亚洲综合激情九月婷婷| 亚洲AV无码专区国产乱码电影 | 夜夜嘿视频免费看| 日本免费xxxx色视频| 国产高清不卡免费视频|