上一页 1 ··· 171 172 173 174 175 176 177 178 179 ··· 491 下一页
摘要: import java.util.* class Animal { var age = 0 get() = field set(value) { if(value >= 0) { field = value } else { throw Error("bad number") } } } fun m 阅读全文
posted @ 2020-10-13 02:27 Zhentiw 阅读(94) 评论(0) 推荐(0)
摘要: enum class Color { RED, GREEN, BLUE } fun main() { println(Color.GREEN) // GREEN } Or give enum a value: enum class Color { RED(0xFF0000), GREEN(0x00F 阅读全文
posted @ 2020-10-12 15:04 Zhentiw 阅读(89) 评论(0) 推荐(0)
摘要: Singleton Object need to be defined as global variable: object Cache { val name= "Cache" fun retrieveDate(): Int { return 0 } } fun main() { println(C 阅读全文
posted @ 2020-10-12 14:58 Zhentiw 阅读(95) 评论(0) 推荐(0)
摘要: If we want to use Class to represent a piece of data such as Object, we can use Data class instead of normal class. Difference: Data class has better 阅读全文
posted @ 2020-10-12 14:56 Zhentiw 阅读(167) 评论(0) 推荐(0)
摘要: interface Lendable { fun borrow() } // The properties title, genre, and publicationYear can be included in the parent class because both books and DVD 阅读全文
posted @ 2020-10-12 14:53 Zhentiw 阅读(92) 评论(0) 推荐(0)
摘要: import java.util.* /** * You can edit, run, and share this code. * play.kotlinlang.org */ abstract class Course(val topic: String, val price: Double) 阅读全文
posted @ 2020-10-12 03:39 Zhentiw 阅读(68) 评论(0) 推荐(0)
摘要: import java.util.* /** * You can edit, run, and share this code. * play.kotlinlang.org */ interface Driveable { fun drive() } interface Buildable { va 阅读全文
posted @ 2020-10-12 03:24 Zhentiw 阅读(148) 评论(0) 推荐(0)
摘要: open class Person (open val name: String = "", open var age: Int) { init {} open fun greeting(pn: String) { println("$name says hello to $pn") } } cla 阅读全文
posted @ 2020-10-11 20:51 Zhentiw 阅读(127) 评论(0) 推荐(0)
摘要: class Person (val name: String, var age: Int) { init {} fun greeting(pn: String) { println("$name says hello to $pn") } } fun main() { val p = Person( 阅读全文
posted @ 2020-10-11 20:34 Zhentiw 阅读(104) 评论(0) 推荐(0)
摘要: fun reverse(numbers: List<Int>): List<Int> { var res = arrayListOf<Int>() for (i in 0..numbers.size-1) { res.add(numbers.get(numbers.size - 1 - i)) } 阅读全文
posted @ 2020-10-11 20:25 Zhentiw 阅读(180) 评论(0) 推荐(0)
上一页 1 ··· 171 172 173 174 175 176 177 178 179 ··· 491 下一页