Confused with the use of assignment “=” and brackets { }

In Groovy, parentheses are sometimes optional.

The first android is passing a closure to a Method. ie:

void android( Closure config ) {
    println "In Android : ${config()}"
}

android {
    'tim'
}

prints : In Android : tim it is the same as calling:

android( {
    'tim'
} )

If you put the parens back.

The second example with minSdkVersion is the same, but it is passing an Integer to a method.

void minSdkVersion( Integer version ) {
    println "In MinSdkVersion : $version"
}

minSdkVersion 19
// same as minSdkVersion( 19 )

So that prints In MinSdkVersion : 19

The last example is setting a property to a String (as you’d expect)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)