【Groovy】入门布道ppt

Groovyhtml

 

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

 

 

跟 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))ide

 

 

闭包
• 调薪函数

 

 

其余
• 构造函数
• ?.操做符(空指针异常)
• *.操做符
• 魔幻数组(+,-,去重,链接)
• 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?.nameui

 

动静皆宜
• @CompileStatic
• @Grab指针

相关文章
相关标签/搜索