forax at univ-mlv.fr
Tue Jun 25 06:46:48 PDT 2013
On 06/25/2013 03:22 PM, Brian Goetz wrote:
>> As someone said one the lambda-dev mailing list, there is no TWR in C#
>> because close is called at the end of the for-each instruction.
>> Why do you want user to care about releasing resources manually if this
>> can be done automatically ?
> Because it can't be.
> What happens if:
> - no one executes a terminal op
This should be flagged by IDEs as useless operation even if there is no
See my answer to Stephan Hermann.
> - a terminal op throws an exception
There is a TWR in the code that loop over the Spliterator in the
> - the user asks for an Iterator/Spliterator and doesn't exhaust it
don't allow an escape hatch on stream that are constructed on an
(there is no such issue if the resource is explicit).
> This is analogous the problem with IO streams, where:
> InputStream is = ...
> isn't good enough; you want try-finally (or TWR) to ensure that
> cleanup happens.
yes, if you explicitly use the InputStream, you have to use a TWR,
if you implicitly uses a resource, instead of using a leaking*
abstraction as you propose (all streams become AutoCloseable),
it's better in my opinion to do the TWR inside the terminal operation.
> What you suggest increases the probability that the stream is closed,
> but doesn't guarantee it.
if you open it and close it in the same terminal operation, there is no
> (It also is far more intrusive in the implementation.)
yes, but I think it can be abstracted if you have a way to represent a
*sorry for the pun
More information about the lambda-libs-spec-observers