title: compile-time checking in Groovy
body: <p>In Groovy types are optional so you can use either:</p>
  
  <pre><code>String foo = "foo"
  foo.noSuchMethod()
  </code></pre>
  
  <p>or</p>
  
  <pre><code>def foo = "foo"
  foo.noSuchMethod()
  </code></pre>
  
  <p>I assumed that the first example would generate a compile-time error, whereas the second would only fail at runtime. However, this doesn't appear to be the case. In my experience, a compile-time error is generated in neither case.</p>
  
  <p>Am I right in assuming then that the only benefit of declaring the type of a reference is as a form of documentation, i.e. to communicate intentions to other programmers. For example, if I write a method such as:</p>
  
  <pre><code>def capitalize(String arg) {
      return arg.toUpperCase()
  }
  </code></pre>
  
  <p>This communicates the type of arguments that should be passed to the function much more effectively than:</p>
  
  <pre><code>def capitalize(def arg) {
      return arg.toUpperCase()
  }
  </code></pre>
  
  <p>Does the Groovy compiler perform any type-checking when types are specified?</p>
  
  <p>Thanks,
  Don</p>