Kotlin Koans - Introduction

Jmnote (토론 | 기여)님의 2019년 3월 27일 (수) 21:12 판 (새 문서: ==Hello, world!== <source lang='kotlin'> fun start(): String = "OK" </source> * Named arguments <source lang='kotlin'> fun joinOptions(options: Collection<String>) = options.joinToStr...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 Hello, world!

fun start(): String = "OK"
  • Named arguments
fun joinOptions(options: Collection<String>) = options.joinToString(", ","[","]")
  • Default arguments
fun foo(name: String, number: Int=42, toUpperCase: Boolean=false) =
        (if (toUpperCase) name.toUpperCase() else name) + number

fun useFoo() = listOf(
        foo("a"),
        foo("b", number = 1),
        foo("c", toUpperCase = true),
        foo(name = "d", number = 2, toUpperCase = true)
)

2 Lambdas

fun containsEven(collection: Collection<Int>): Boolean = collection.any { it%2==0 }

3 Strings

4 Data classes

5 Nullable types

6 Smart casts

7 Extension functions

8 Object expressions

9 SAM conversions

10 Extensions on collections

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}