examples/groovy/casting_string_to_integer.groovy



def x = "23"

println(x + 4)  // 234

def y = x as Integer
println(y + 4)        // 27

println((x as Integer) + 4)  // 27

examples/groovy/casting_arraylist_to_string.groovy


def names = ['Foo', 'Bar']
z = names as String
println(names)   // [Foo, Bar]
println(z)       // [Foo, Bar]

println(names.getClass())   // class java.util.ArrayList
println(z.getClass())       // class java.lang.String