[JSR308] annotations on expressions and literal values

Eugene Kuleshov eu at javatx.org
Wed Jan 31 15:03:48 EST 2007


Michael Ernst wrote:
>> Object result = engine.eval(
>>     "fib(num);" +
>>     "function fib(n) {" +
>>     "  if(n <= 1) return n; " +
>>     "  return fib(n-1) + fib(n-2); " +
>>     "};" @Script("JavaScript"),
>>     bindings);
>>     
> Annotations on types already permit this this using a cast:
>
> Object result = engine.eval(
>     (@Script("JavaScript") String)       // <--- this is the cast
>     "fib(num);" +
>     "function fib(n) {" +
>     "  if(n <= 1) return n; " +
>     "  return fib(n-1) + fib(n-2); " +
>     "};",
>     bindings);
>
> One advantage of the cast syntax is that it does not introduce new syntax.
>   
  That makes sense, though cast on String value is somehow redundant in 
this case, because we already have type-safe construct.

  On the other hand, it seems like its presentation in the bytecode is 
sufficient.

  regards,
  Eugene





More information about the JSR308 mailing list