Used with any object that contains a close() method that
returns nothing, withCloseable() executes a block of code
with the closeable object, ensuring that the object is closed no
matter what.
Used with any object that contains a close() method that
returns nothing, withCloseable() executes a block of code
with the closeable object, ensuring that the object is closed no
matter what. It allows you to replace code like this:
val closeableObject = ... try { doSomethingWith(closeableObject) } finally { closeableObject.close }
with:
withCloseable(closeableObject) { closeable =>
doSomethingWith(closeable)
}the closeable object
the block of code, which will take the closeable object
and return some arbitrary type R.
whatever the code block returns,if anything.
Miscellaneous utility functions and methods not otherwise categorized.