title: When a method with varargs is called with an array as argument in Groovy, what's the argument treated as on earth?
body: <p>It's either the origin array or an one-element long array containing the origin array.</p>
  
  <p>As <a href="http://www.groovy-lang.org/objectorientation.html#_varargs" rel="nofollow">GLS</a> said, it's the origin one:</p>
  
  <blockquote>
    <p>If a varargs method is called with an array as an argument, then the argument will be that array instead of an array of length one containing the given array as the only element.</p>
  </blockquote>
  
  <pre><code>def foo(Object... args) { args }
  Integer[] ints = [1, 2]
  assert foo(ints) == [1, 2]
  </code></pre>
  
  <p>but when I wrote this snippet and executed it on GroovyConsole,</p>
  
  <pre><code>def foo(Integer... args) { args?.length }
  assert foo(null) == null
  assert foo() == 0
  assert foo(0,1,2) == 3
  assert foo([0,*(4..6)]) != 3
  </code></pre>
  
  <p>It gave me the opposite answer:</p>
  
  <pre><code>org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[0, 4, 5, 6]' with class 'java.util.ArrayList' to class 'java.lang.Integer'
  at sample.run(sample.groovy:107)
  </code></pre>
  
  <p>so I spread the array on the last statement, then it worked.</p>
  
  <pre><code>assert foo(*[0,*(4..6)]) != 3
  </code></pre>