gradle 实例代码

public class CompareSize{
    private int max
    private int min

    public CompareSize(int max, int min) {
        this.max = max
        this.min = min
    }

    public int getMajor() {
         major
    }

    public void setMajor(int major) {
        this.major = major;
    }
}
CompareSize v1=new CompareSize(1,1)
println v1.max;
CompareSize v2=null
println v2==v1

//groovy 高效特性

//1可选的类型定义

def ver=1

//2 assert

//assert version==2

//3 括号是可选的

println ver

//4 字符串

def s1='mwzhyf'  //仅仅是字符串

def s2="mwzhyf  is ${version}" //可以插入变量

def s3='''mw

love

zhyf''' //可以换行

println s1
println s2
println s3
//5 集合api

//list

def buildTools=['ant','maven']

buildTools << 'gradle'

assert buildTools.getClass()==ArrayList

assert buildTools.size()==3

//map

def buildleYears=['ant':20,'maven':24]

buildleYears.gradle=29

println buildleYears.ant

println buildleYears['gradle']

println buildleYears.getClass()
//​ 6 闭包 代码块

def c1={

    v->

        print v

}

def c2={

    print 'ho'

}

def method1(Closure closure){

    closure('par')

}

def method2(Closure closure){

    closure()

}

method1(c1);

method2(c2);

猜你喜欢

转载自blog.csdn.net/xiaofanren1111/article/details/80957632