zoukankan      html  css  js  c++  java
  • 【Groovy】入门布道ppt

    Groovy

    Outline
    • Hello world
    • Smooth Java integration
    • Flat learning curve
    • Powerful features

    跟 Java ⽆无缝集成
    • 呃, 实际上还是有⼀一点差别的, 看这⾥里http://www.groovy-lang.org/differences.html
    • 实际项⺫⽬目展⽰示

    平滑的学习曲线
    • Style guide  http://www.groovy-lang.org/style-guide.html 
    • Design patterns http://www.groovy-lang.org/design-patterns.html

    反射
    import org.springframework.util.ReflectionUtils;
    Method[] methods = ReflectionUtils.getAllDeclaredMethods(interfaceClazz);
    Method method = null;
    for (Method m : methods) {
    if (methodName.equals(m.getName())) {
    method = m;
    break;
    }
    }
    if (method != null) {
    if (params != null && !"null".equals(params)) {
    Type[] paramTypes = method.getGenericParameterTypes();
    val = ReflectionUtils.invokeMethod(method, service, deserialize(params,
    paramTypes).toArray());
    } else {
    val = ReflectionUtils.invokeMethod(method, service);
    }
    } else{
    throw new MethodNotFoundException();
    }
    —————————————————————————————————————————————————————————————————————————————————————————————————————
    Type[] paramTypes = interfaceClazz.methods.find{
    it.name == methodName
    }.getGenericParameterTypes()
    val = service."$methodName"(* deserialize(params,paramTypes))

    闭包
    • 调薪

    其他
    • 构造函数
    • ?.操作符(空指针异常)
    • *.操作符
    • 魔幻数组(+,-,去重,连接)
    • with ⽅方法
    • @Category与@Mixin
    • 综合(获取购物⻋车中所有总价⼤大于7000的商品名称)

    class Cart{
    • List cartItems
    • }
    • class CartItem{
    • Product product
    • int amount
    • }
    • class Product{
    • String name
    • int price
    • }
    • new Cart(
    • cartItems:[
    • new CartItem(product:new Product(name:"aa",price:4000),amount:2),
    • new CartItem(product:new Product(name:"bb",price:3000),amount:20)
    • ]
    • ).cartItems.grep{
    • it.product.price * it.amount > 7000
    • }.product?.name

    动静皆宜
    • @CompileStatic
    • @Grab

  • 相关阅读:
    ubuntu国内镜像源
    windows安装Pygraphviz
    python dict与collections.defaultdict的区别
    python生成 requirements.txt文件
    python list 和 dict前加星号
    Ubuntu安装Docker
    Zookeeper核心概念及读写流程
    docker安装mysql5和mysql8
    ubuntu docker更改默认镜像和容器存储位置
    训练篇-胸
  • 原文地址:https://www.cnblogs.com/viewcozy/p/4763645.html
Copyright © 2011-2022 走看看