The use Function

Learn about the use function in Kotlin.

We'll cover the following

In addition to the generic scoping functions mentioned earlier, there are a number of similar functions in Kotlin that are less generic but have a specific purpose.

The use function

The use function is the counterpart to Java’s try-with-resourcestrywithresources statement, which allows us to encapsulate AutoClosable resources in a more readable way than ordinary try-catch blocks.

Get hands-on with 1200+ tech skills courses.