title: Defining a Method inside Groovy used in Java
body: <p>I'm using <strong>Groovy Interpreter</strong> in <strong>Java</strong> <code>class</code>, I'm trying to define a method and call it, here is my code:</p>
  
  <pre><code>        Binding binding = new Binding();
          binding.setVariable("aa", 1);
          binding.setVariable("bb", 2);
  
          GroovyShell shell = new GroovyShell(binding);
          shell.evaluate("int add(int a,int b){return (a+b)}");
  
          int   value =(int) shell.evaluate("add(aa,bb);");
          System.out.println(value);
  </code></pre>
  
  <p>And I've got this error:</p>
  
  <blockquote>
    <p>Exception in thread "main" groovy.lang.MissingMethodException: No
    signature of method: Script2.add() is applicable for argument types:
    (java.lang.Integer, java.lang.Integer) values: [1, 2] Possible
    solutions: any(), wait(), run(), run(), find(), wait(long, int)</p>
  </blockquote>
  
  <p>Please tell me how to define a function inside groovy and why my code is not working.</p>
  
  <p>Best regards,</p>