class를 확장해서 사용하는 개념; java의 후행 lambda 개념..?
fun String.append(toAppend: String):String = this.plus(toAppend)
fun String.removeFirstAndLastChars() : String = this.substring(1, this.length -1)
println("Hello Jenny".append(" you are my friend"))
println("this is fun".removeFirstAndLastChars())
//fun String.append(toAppend: String):String {
// return this.plus(toAppend)
//}
'kotlin' 카테고리의 다른 글
kotlin - enum , object, state 관리(외부 접속 시) -> abstract class(interface)로 변경 -> sealed class/interface로 변경 (0) | 2023.03.27 |
---|---|
kotlin - generic (0) | 2023.03.27 |
Kotlin Collection Functions Cheat Sheet (0) | 2023.03.27 |
kotlin 범위 지정 함수 : run/let, apply/also, with (0) | 2023.03.26 |
kotlin - lambda (0) | 2023.02.13 |