![]() * Every element in this set has a unique. * An indexed set is a mix between a set and a map. ![]() To kick this article off, let's take a look at the declaration of CoroutineContext: /** In Part 1 of my series about coroutines, I will take a close look at the CoroutineContext and discuss the best practices on how to use it. However, given its nature and flexible API, it might prove pretty tricky to use it correctly. Every coroutine you launch will have a context. There are a few differences, but we’ll leave them for a later chapter.The CoroutineContext is the backbone of the coroutines library. As you can see, the syntax for generics is very similar to Java. The function is generic: it works on collections that contain elements of any type. The function just appends the elements of the collection to a StringBuilder, with a separator between them and surrounded by prefix and postfix. Let’s introduce the function joinToString without using any of Kotlin’s new features in this area, and then rewrite it in a more idiomatic style. Imagine we need the elements to be separated by semicolon and surrounded by round brackets instead of the default square ones: > println(joinToString(list, " ", "(", ")")) (1 2 3) > val list = arrayListOf(1, 2, 3) > println(list) ❶ The Kotlin standard library is no exception. Almost every project has its own StringUtil class with a bunch of functions including joinToString. Java collections have a default toString implementation, but its output is fixed and it’s not always what you need. In this article, excerpted from Kotlin in Action,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |