kotlin

kotlin extension Function

slow333 2023. 3. 27. 20:59

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)
//}