Kotlin의 특징
- JVM 언어와 100% 호환되는 프로그래밍 언어
- 직관적이고 간결한 문법
- Null 처리에서 높은 안정성
Java와 무엇이 다른가요?
Kotlin 공식 사이트에서는 Java 대신 Kotlin을 사용할 때의 이점을 이렇게 말하고 있습니다.
Kotlin is more concise. Rough estimates indicate approximately a 40% cut in the number of lines of code. It's also more type-safe, for example, support for non-nullable types makes applications less prone to NPE's. Other features including smart casting, higher-order functions, extension functions and lambdas with receivers provide the ability to write expressive code as well as facilitating creation of DSL.
1. 간결함
코드 라인 수가 40% 정도 감소합니다.
2. type-safe
non-nullable 타입을 지원해 NPE(Null Point Exception)에 덜 취약합니다.
3. expressive, DSL(Domain-Specific Languages, 도메인 특화 언어)
expressive 한 코드를 작성하고, 도메인에 특화된 언어를 생성하도록 합니다.
예시로 든 기능들입니다.
smart casting : 자료형을 명시하지 않아도 컴파일러가 자동으로 변환
higher-order functions : 고차함수. 람다나 함수 참조를 인자로 받거나 반환
extension functions : 확장함수. 상속이나 별도의 디자인 패턴 없이 객체를 확장해 정의
lambdas with receivers : 수신 객체 지정 람다. 수신 객체를 반복적으로 명시하지 않고도 람다의 본문 안에서 다른 객체의 메소드를 호출
+ 참고
Kotlin 코딩 컨벤션
https://developer.android.com/kotlin/style-guide?hl=ko
'Kotlin' 카테고리의 다른 글
[Kotlin] 재귀 함수와 반복문, 그리고 꼬리 재귀(tailrec) (0) | 2023.12.12 |
---|---|
호텔 예약 콘솔 프로그램에서 체크인/체크아웃 날짜 검증하기 (0) | 2023.12.11 |
[Kotlin] Array 생성자를 이용해 array 만들기 (1) | 2023.12.07 |
[Kotlin] 지연 초기화란? (0) | 2023.12.06 |