【Groovy】《Groovy in action, Second Edition》待研究基础知识及技术实现

算法

尾递归优化

《Groovy in action, Second Edition》P385

  • 是什么?
  • 在什么场景下用?

AST 语法树(不常用)

技术

高层级的并发技术GPars

  • 是什么?
  • 怎么用?

Groovy 锁的应用场景

  • @Synchronized
  • @WithWriteLock
  • @WithReadLock

trait 用来组合一个对象

  • 应用场景?

DSL 的业务实战

参考至github

  • 尝试取代Mysql的单表规则配置,转而用DSL描述规则 EG:
onConsume = {
    reward ( "观看迪斯尼的电影, 你可以获得 25%的积分." ) {
        allOf {
            condition {
                media.publisher == "Disney"
            }
            condition {
                isVideo
            }
        }
        anyOf {
           condition {
                
            }
            condition {
                
            }
        }
        grant {
            points media.points / 4
        }
    }

    reward ( "查看新发布的媒体,可以延长一天" ) {
        condition {
            isNewRelease
        }
        grant {
            extend 1
        }
    }
}
  • 搞清楚闭包 delegate ; this; 的应用场景 EG:
// 这里的this赋值给delegate,是让新执行的脚本能够得到当前类中binding存的上下文信息
GroovyShell shell = new GroovyShell(binding)
shell.evaluate("onConsume.delegate=this; onConsume()")

// closure.delegate = delegate github代码中不加也不影响实现,具体什么时候该加要积累一下
binding.reward = { spec, closure ->
        closure.delegate = delegate
        binding.result = true
        // anyOf allOf condition 之间的连接关系默认是and
        binding.and = true
        closure()
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Groovy in Action, Second Edition is the undisputed definitive reference on the Groovy language. Written by core members of the Groovy language team, this book presents Groovy like no other can—from the inside out. With relevant examples, careful explanations of Groovy's key concepts and features, and insightful coverage of how to use Groovy in-production tasks, including building new applications, integration with existing code, and DSL development, this is the only book you'll need. Updated for Groovy 2.4. Some experience with Java or another programming language is helpful. No Groovy experience is assumed. Table of Contents Part 1 The Groovy language Chapter 1 Your way to Groovy Chapter 2 Overture: Groovy basics Chapter 3 Simple Groovy datatypes Chapter 4 Collective Groovy datatypes Chapter 5 Working with closures Chapter 6 Groovy control structures Chapter 7 Object orientation, Groovy style Chapter 8 Dynamic programming with Groovy Chapter 9 Compile-time metaprogramming and AST transformations Chapter 10 Groovy as a static language Part 2 Around the Groovy library Chapter 11 Working with builders Chapter 12 Working with the GDK Chapter 13 Database programming with Groovy Chapter 14 Working with XML and JSON Chapter 15 Interacting with Web Services Chapter 16 Integrating Groovy Part 3 Applied Groovy Chapter 17 Unit testing with Groovy Chapter 18 Concurrent Groovy with GPars Chapter 19 Domain-specific languages Chapter 20 The Groovy ecosystem Appendix A Installation and documentation Appendix B Groovy language information Appendix C GDK API quick reference Appendix D Cheat sheets Appendix E Annotation parameters Appendix F Compiler phases Appendix G AST visitors Appendix H Type checking extensions Appendix I Android support

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值