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")


上一篇:
下一篇:
切换中文