title: How does Groovy translate from char[] to String within a GString?
body: <p>I'm trying to figure out how Groovy translates a <code>char[]</code> to a <code>String</code> within a <code>GString</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>char[] pchar = ['p', 'a', 's', 's']
  println "$pchar"
  </code></pre>
  
  <p>Result: </p>
  
  <p><em>pass</em></p>
  
  <p>At first I assumed it would use the toString() method on char[] (http://groovy.codehaus.org/groovy-jdk/primitive-types/char[].html#toString()). But the results of running the following code seems to suggest otherwise:</p>
  
  <pre><code>char[] pchar = ['p', 'a', 's', 's']
  println "$pchar"
  
  pchar.class.metaClass.toString = {-&gt;
      "****"
  }
  
  println pchar.toString()
  println "$pchar"
  </code></pre>
  
  <p>Result:</p>
  
  <p><em>pass</em></p>
  
  <p>****</p>
  
  <p><em>pass</em></p>
  
  <p>I've also tried overriding <code>invokeMethod()</code> to try figuring it out to no avail:</p>
  
  <pre><code>char[] pchar = ['p', 'a', 's', 's']
  println "$pchar"
  
  pchar.class.metaClass.toString = {-&gt;
      "****"
  }
  pchar.class.metaClass.invokeMethod = {String methodName, Object arguments -&gt;
      println("Method called on ${delegate.class}: $methodName, $arguments")
      def metaMethod = delegate.metaClass.getMetaMethod(methodName)
      return metaMethod.invoke(delegate, arguments)
  }
  
  println pchar.toString()
  println "$pchar"
  </code></pre>
  
  <p>Result:</p>
  
  <p><em>pass</em></p>
  
  <p><em>Method called on class [C: toString, []</em></p>
  
  <p>****</p>
  
  <p><em>pass</em></p>
  
  <p>Does anyone know how Groovy does this transformation?</p>