java - Kotlin: appendText and closing resources -


i'm new kotlin, have strong java background (java day job). i'm loving of shortcut functions in kotlin. 1 of big ones file.appendtext(). it's convenient, imo.

my question closing resources. if use writer, this:

out8.writer().use { ... } 

but don't see thing directly on appendtext method indicates closing resources. kotlin handle behind scenes me, or have worry in way?

thanks.

you can jump implementation of appendtext in ide find out (ctrl + b on windows, ⌘b on mac).

here's implementation of method:

public fun file.appendtext(text: string, charset: charset = charsets.utf_8): unit      = appendbytes(text.tobytearray(charset)) 

and here's appendbytes method delegates work to:

public fun file.appendbytes(array: bytearray): unit      = fileoutputstream(this, true).use { it.write(array) } 

you can see uses use helper method you've expected.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -