title: Difference between Groovy def and Java Object?
body: <p>I'm trying to figure out the difference between </p>
  
  <p>Groovy:</p>
  
  <pre><code>def name = "stephanie"
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>Object name = "stephanie"
  </code></pre>
  
  <p>as both seem to act as objects in that to interact with them i have to cast them to their original intended type.</p>
  
  <p>I was originally on a search for a java equivalent of C#'s dynamic class ( <a href="https://stackoverflow.com/questions/3935832/java-equivalent-to-c-dynamic-class-type">Java equivalent to C# dynamic class type?</a> ) and it was suggested to look at Groovy's <code>def</code> </p>
  
  <p>for example my impression of groovy's def is that I could do the following:</p>
  
  <pre><code>def DOB = new Date(1998,5,23);
  int x = DOB.getYear();
  </code></pre>
  
  <p>however this wont build</p>
  
  <p>thanks,steph</p>
  
  <p>Solution edit:
  Turns out the mistake iw as making is I had a groovy class wtih public properties (in my example above DOB) defined with def but then was attemping to access them from a .java class(in my example above calling .getYear() on it). Its a rookie mistake but the problem is once the object leaves a Groovy file it is simply treated as a Object. Thanks for all your help!</p>