after `use` execution both first and second will b...
# announcements
c
after
use
execution both first and second will be closed, so the object becomes unusable. I'm sorry for so many uses of the word 'use', but here I kinda have to 😄
m
Why can't you just do the nesting inside the
use
function, instead of implementing manually. The whole implementation would be this:
first.use { a -> second.use { b -> useBlock(a, b) } }
.
c
I'm just solving theoretical a problem as it is formulated by Olekss. If I needed to use two closeables I would've used nesting as you suggest. This is just esoteric practice 🙂
m
Yes, I know that 😉 I'm just suggesting that the implementation of the
use
function in
UsablePair
could just be what I wrote in my last comment. You don't really need that big try-catch statement.
b
IMO, two nested statements is not "big"
m
No, I was referring to the try-catch as "big".
c
Oh, I see now, you definitely make a good point. I deliberately didn't want to use
use
. Wanted to see how implementation from scratch would look like.