본 글은 https://kotlinlang.org/docs/home.html 를 기반으로 작성자 마음대로 번역한 글입니다.
오역 & 의역이 빈번하며 모든 질문 및 태클 환영합니다!
2022-01-15 기준으로 작성되었습니다.
Create DTOs (POJOs / POCOs)
Customer 클래스는 다음 기능을 제공합니다.
- 모든 프로퍼티에 대한 getters (var일 경우 setters)
- equals()
- hashCode()
- toString()
- copy()
- component1(), component2(), ..., 모든 프로퍼티 (Data classes↗)
Default values for function parameters
Filter a list
더 짧게 :
defference between Java and Kotlin filtering↗
Check the presense of an element in a collection
String interpolation
difference between Java and Kotlin string concatenation↗
Instance checks
Read-only list
Read-only map
Access a map entry
Traverse a map or a list of pairs
k와 v는 name과 age 같은 더 좋은 이름으로 변형할 수 있습니다.
Iterate over a range
Lazy property
Extension functions
Create a singleton
Instantiate an abstract class
If-not-null shorthand
If-not-null-else shorthand
Execute a statement if null
Get first item of a possibly empty collection
Execute if not null
Map nullable value if not null
Return on when statement
try-catch expression
if expression
Builder-style usage of methods that return Unit
Single-expression functions
는 다음과 동일합니다.
다른 관용구와의 결합은 효과적으로 코드를 줄일 수 있습니다.
다음은 when 표현식을 사용한 예시입니다.
Call multiple methods on an object instance (with)
Configure properties of an object (apply)
생성자에 없는 프로퍼티를 구성하기에 좋습니다.
Java 7's try-with-resources
Generic function that requires the generic type information
Nullable Boolean
Swap two variables
Mark code as incomplete (TODO)
코틀린 표준 라이브러리의 TODO() 함수는 NotImplementedError을 throw합니다.
return type은 Nothing으로 유형에 관계 없이 사용할 수 있습니다.
IntelliJ IDEA의 코틀린 플러그인은 TODO()를 인지하여 TODO 툴 윈도우에 코드 포인터를 자동으로 추가합니다.
https://kotlinlang.org/docs/idioms.html
Idioms | Kotlin
kotlinlang.org
'Kotlin > Docs' 카테고리의 다른 글
[Kotlin Docs] Conditions and loops (0) | 2022.01.19 |
---|---|
[Kotlin Docs] Type checks and casts (0) | 2022.01.19 |
[Kotlin Docs] Basic types (0) | 2022.01.18 |
[Kotlin Docs] Coding conventions (0) | 2022.01.17 |
[Kotlin Docs] Basic syntax (0) | 2022.01.14 |