Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is the difference between launch/jo...

Câu trả lời

The main differences between launch/join and async/await in Kotlin coroutines are:

  • launch returns a Job and is used to start a coroutine that doesn't return a result, while async returns a Deferred<T> and is used to start a coroutine that computes and returns a result[1][4][5].

  • join() is used to wait for a coroutine started with launch to complete, while await() is used to retrieve the result of a coroutine started with async[1][2][3].

  • If an exception occurs in a coroutine started with launch, it is propagated and can crash the application if not handled. With async, exceptions are stored in the Deferred and must be explicitly handled[4][5].

  • launch is useful for fire-and-forget tasks that don't need to return a value, while async is better for tasks that compute a result that will be used later[1][4].

  • Both launch and async can be used to...

expert

expert

Gợi ý câu hỏi phỏng vấn

expert

What is a motivation to make classes final by default in Kotlin? Do you agree with that decision?

middle

Explain advantages of when vs switch in Kotlin

middle

What is the idiomatic way to deal with null able values, referencing or converting them?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào