긴 이름의 클래스 혹은 함수 타입이 있을 때 축약하거나 더 좋은 이름을 쓰고 싶다.
typealias FruitFilter = (Fruit) -> Boolean
fun filterFruits(fruits: List<Fruit>, filter: FruitFilter) {
}
data class UltraSuperGuardianTribe(
val name: String
)
typealias USGTMap = Map<String, UltraSuperGuardianTribe>
다른 패키지의 같은 이름 함수를 동시에 가져오고 싶다면?
import main.com.lec19.a.printHelloWorld as printHelloWorldA
import main.com.lec19.b.printHelloWorld as printHelloWorldB
fun main() {
printHelloWorldA()
printHelloWorldB()
}
구조문해: 복합적인 값을 분해하여 여러 변수를 한 번에 초기화하는 것
data class Person(
val name: String,
val age: Int
)
fun main() {
val person = Person("류욱상", 100)
val (name, age) = person
val name2 = person.component1()
val age2 = person.component2()
}
특정 Expression에 ‘라벨이름@’을 붙여 하나의 라벨로 간주하고 break, continue, return 등을 사용하는 기능이다.
loop@ for (i in 1..100) {
for (j in 1..100) {
if (j == 2) {
break@loop
}
print("$i $j")
}
}
라벨을 사용한 Jump는 사용하지 않는것을 강력추천!!!
코드의 상하로의 움직임이 많아질수록 복잡도가 매우 드라마틱하게 증가하기때문.