Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Using a tagging interface



When you are creating your ScriptWrapper, it is possible to use an interface without any method. For example with the following script interface:
      public interface Script {
      }      
This code is perfectly valid:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
      };            

Limitation

Of course, in this use case, you won't be able to execute methods by using the Script proxy, because no method have been defined in the interface. For example, even if your script file is:
      public int computeResult(int value) {
        return value * 10;
      }   
You won't be able to compile:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
      };      
      File file = new File(<our script file>);
      wrapper.installScript(file);

      int value = script.computeResult(10);
Because the computeResult(int value) does not exist in the script.

Usage with Method invocation

When you use an interface without any method, you will perfectly be able to use yout script by Method invocation. For example, in the above use case, this is perfectly valid:
      File file = new File(<our script file>);
      wrapper.installScript(file);
      wrapper.logExceptions(true);
      
      Object result = wrapper.invokeMethod("computeResult", 1);
      // result is the Integer 1

See also


Categories: api

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence