0
cursor?.apply{
    this.moveToFirst() 
}

cursor?.use{
    it.moveToFirst() 
}

The only difference I see is between it and this, that is the same instance. But, is there any other difference?

1 Answer 1

3

use() can only be called with a Closeable receiver. After the block is executed, the Closeable resource is closed, which saves boilerplate.

You can see https://kotlinlang.org/docs/scope-functions.html for more information on all the scope functions. use() is essentially the same as let(), except with the addtional auto-closing feature.

Sign up to request clarification or add additional context in comments.

1 Comment

Maybe you can add that apply returns the context object and you can add the doc links for apply and use.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.