println args
println args.size()
println args.each{arg-> println arg}
println args.class
if (args.contains("Hello"))
println "Found Hello"
Run Code Online (Sandbox Code Playgroud)
当运行时给出以下错误:
[hello, somethingelse]
2
hello
somethingelse
[hello, somethingelse]
class [Ljava.lang.String;
Caught: groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.
String;.contains() is applicable for argument types: (java.lang.String) values:
[Hello]
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做contains?
Myk*_*yev 15
因为args是String[]但不List<String>
您可以使用
if (args.grep('Hello'))
println "Found Hello"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27247 次 |
| 最近记录: |