공부/Kotlin
-
Kotlin in action - 코틀린 기초공부/Kotlin 2021. 1. 3. 15:47
Hello world! fun main(args: Array) { println("Hello world!") } 함수를 선언할 때 fun 키워드 사용. 파라미터 이름 뒤에 타입을 선언. 함수를 최상위 수준에 정의할 수 있다. 배열 처리를 위한 문법이 따로 존재하지 않는다. 코틀린 표준 라이브러리가 있어, 여러 자바 함수들을 간결하게 사용할 수 있게 wrapper 제공한다. ex ) println (System.out.println 의 wrapper 함수) 세미콜론을 붙히지 않아도 된다! 함수 fun max(a: Int, b: Int): Int { return if (a > b) a else b } 리턴 타입을 파라미터 목록 뒤에 콜론으로 구분 후 선언 문과 식의 구분 코틀린에선 if 는 식이지 문이 아니..