kotlin
fun String.myLength(): Int {
return this.length
}
kotlin
val str = "Hello, World!"
val length = str.myLength()
println("Length of '$str' is $length")
kotlin
val Date.formattedDate: String
get() {
val sdf = SimpleDateFormat("yyyy-MM-dd")
return sdf.format(this)
}
kotlin
val currentDate = Date()
val formattedDate = currentDate.formattedDate
println("Formatted date is $formattedDate")