I tried to invoke method "findResults" on a split String, but got a compilation error. Splitting a String returns a String Array, which I thought would be regarded as a Collection in Groovy. Other Collection methods do work on a String Array, so my question is: have I encountered a bug?
def names = "john paul pete"
assert names.split().findResults{if (it.startsWith("p")) return it.capitalize()}.join(" ") == "Paul Pete"
Result: groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.String;.findResults() is applicable for argument types: (gard_split_check$_run_closure2) values: [gard_split_check$_run_closure2@722b302]
NB I know I can get the proper result by replacing split() with tokenize() in the above code, or by casting the result of the split() method to a List.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.