uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject Re: [jira] [Created] (UIMA-4135) support for modifying indexed FSs
Date Mon, 01 Dec 2014 23:30:20 GMT
The anonymous inner class has a nice property that with Java 8 you can use lambdas.

A problem, though, I think is how to nicely handle thrown checked exceptions. 
With lambdas, I think you can't have checked exceptions.  With anonymous inner
classes, you can.  But of course the syntax is more difficult to understand.

I'm not sure about the abuse part for try / finally.  (I'm not using try /catch
:-) ).  The try / finally is for the purpose of putting a block scope around
some code, and then executing some code at the end of a block, even if an
exception is thrown. 

I need the signal of where the end of the block is, and to execute code there,
in order to add-back any FSs that might have been removed (if needed) in the
body of the code while doing the feature updates.

It seems that the try / finally (or Java 8's try with resources) has a clearer
syntax for specifying this than anything else I've thought of (but maybe there's
still a better way :-) ).


On 12/1/2014 4:09 PM, Richard Eckart de Castilho wrote:
> On 01.12.2014, at 19:24, Marshall Schor <msa@schor.com> wrote:
>> One approach would use the try/ finally form:
>>  controlVar = cas.startUimaIndexProtectedBlock();
>>  try {
>>    some code which modifies a FS (or maybe, multiple FSs
>>  } finally {
>>    controlVar.close();  // causes any "removes" to be now re-added to indices
>>  }
>> A form like the above could use in Java 8 the simpler try-with-resources form:
>>  try (controlVar = cas.startUimaIndexProtectedBlock()) {
>>    some code which modifies a FS (or maybe, multiple FSs
>>  }
> For me, this smells a but like abusing try/catch, although I admit that
> it also has some elegance.
> Why not use an anonymous inner class like this:
> cas.transaction(new Transaction<CAS>() {
>   void perform(CAS cas) {
>     // make modifications
>   }
> });
> Afaik this works also in Java versions prior to 7. It's the kind of thing
> one did before lambda arrived.
> Cheers,
> -- Richard

View raw message