Docs: improve docs for Closeable.use and AutoCloseable.use

This commit is contained in:
Ilya Gorbunov
2016-07-13 19:38:37 +03:00
parent b09fc7c146
commit e9ccc480b0
2 changed files with 12 additions and 3 deletions
@@ -1,6 +1,16 @@
@file:JvmName("StandardJRE7Kt")
package kotlin
/**
* Executes the given [block] function on this resource and then closes it down correctly whether an exception
* is thrown or not.
*
* In case if the resource is being closed due to an exception occurred in [block], and the closing also fails with an exception,
* the latter is added to the [suppressed][java.lang.Throwable.addSuppressed] exceptions of the former.
*
* @param block a function to process this [AutoCloseable] resource.
* @return the result of [block] function invoked on this resource.
*/
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.InlineOnly
public inline fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R {
+2 -3
View File
@@ -143,13 +143,12 @@ public inline fun URL.readText(charset: Charset = Charsets.UTF_8): String = read
*/
public fun URL.readBytes(): ByteArray = openStream().use { it.readBytes() }
// TODO: Provide use kotlin package for AutoCloseable
/**
* Executes the given [block] function on this resource and then closes it down correctly whether an exception
* is thrown or not.
*
* @param block a function to process this closable resource.
* @return the result of [block] function on this closable resource.
* @param block a function to process this [Closeable] resource.
* @return the result of [block] function invoked on this resource.
*/
@kotlin.internal.InlineOnly
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {