zoukankan      html  css  js  c++  java
  • Groovy A simple DSL based on groovy

    import groovy.transform.Field;
     
    @Field def eat = new Expando()
     
    class FriendHadnler {
        def scriptObject
     
        void friend(String name) {
            scriptObject.eat.friend = name
        }
    }
     
    @Field def friendHadnler = new FriendHadnler(scriptObject : this)
     
    void place(String place) {
        eat.place = place
    }
     
    void time(String time) {
        eat.time = time
    }
     
    void withFriend(Closure cl) {
        cl.setResolveStrategy(Closure.DELEGATE_FIRST)
        cl.setDelegate(friendHadnler)
        cl.call()
    }
     
    def eatSth(Closure cl) {
        cl.call()
        println eat.place + ' ' + eat.time + ' with friend ' + eat.friend
    }
     
    eatSth {
        place     'meituan tower'
        time      '12:30 pm'
        withFriend {
            friend 'han meimei'
        }
    }
    

      

  • 相关阅读:
    动态规划练习 7
    面试经验交流感悟
    反转链表
    动态规划练习 6
    动态规划练习 4
    动态规划练习 9
    动态规划练习 12
    动态规划练习 8
    动态规划练习 13
    动态规划练习 11
  • 原文地址:https://www.cnblogs.com/lotusJade/p/4881944.html
Copyright © 2011-2022 走看看