세미콜론은 생략해도 된다.
변수 타입 지정은 생략해도 된다. (타입 추론이 가능하다.)
// typeinference.kts
val greet = "hello"
println(greet) // hello
println(greet::class) // class kotlin.String
println(greet.javaClass) // class java.lang.String
클래스와 함수는 생략 가능하다
//standalone.kts
fun nofluff() {
println("nofluff called...")
throw RuntimeException("oops")
}
println("not in a function, calling nofluff()")
try {
nofluff()
} catch(ex: Exception) {
val stackTrace = ex.getStackTrace()
println(stackTrace[0])
println(stackTrace[1])
}
/**
* Result
* not in a function, calling nofluff()
* nofluff called...
* Standalone.nofluff(standalone.kts:4)
* Standalone.<init>(standalone.kts:10)
* */
Try-Catch는 선택사항이다.
<애자일 Practice>
경고를 오류처럼 다루는 것이 올바른 소프트웨어 개발 습관이다.