Kotlin은 얼마나 좋을까? 백엔드에 적용했을 때 어떤 이점이 있을까?
컴파일 언어를 스크립트 언어보다 선호합니다. 런타임이 아닌 컴파일 타임에 예외를 발생시키는 언어가 더 좋은 언어라고 생각합니다.
is, as)
자바에서는 Lombok을 통해 줄이는 소스 코드들을 data class 제공
Immutable이 기본Default Arguments
String template(Sacla - string interpolation
Properties(C#, No Getter-Setter)
Extension Functions
fun Int.millis(): Duration = Duration.ofMillis(this.toLong())
fun Int.seconds(): Duration = Duration.ofSeconds(this.toLong())
// 5.seconds() + 400.millis() -> 5400 msec
Null Safety
// Elvis Operaion in Kotlin
if(text != null) test.length else -1
text?.length ?: -1
// java
if(command!=null) {
if(command.getThreadPoolProperites()!=null) {
if(command.getThreadPoolProperites().maxQueueSize()!=null){
val x = command.getThreadPoolProperites().maxQueueSize().get()
}
}
}
// kotlin
val x = command?.getThreadPoolProperites()?.maxQueueSize()?.get() ?:0
async, await 키워드 두개만 추가하면 Sync, Async가 바뀐다suspend, async(), await()gofinal 이기 때문에