Groovy Array of Strings -


i know curly brackets not used initialize array in groovy have noticed 1 peculiar thing.

why groovy doesn't give compiler error when initialize array this.

string emailaddress = "test@gmail.com";  string [] var = {emailaddress};  println var[0]; 

output: com.test.examples.groovytest$_main_closure1@12e4860e

when try declare error:

string [] var = {"a","b"}; 

can explain this?

when do:

string [] var = {emailaddress}; 

that creates closure returns string emailaddress, , crams closure string array (by calling tostring() on it), that's told ;-)

so var equals ['consolescript0$_run_closure1@60fd82c1'] (or similar, depending on you're running things)

when do:

string [] var = {"a","b"}; 

the right-hand side not valid closure, script fails parse.

what want is:

string[] var = ['a', 'b'] 

or:

string[] var = [emailaddress] 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -