1.
lateinit var nameView:TextView
val nameTextView by lazy {
findViewById<TextView>(R.id.tv_content)
}
2.
class Person(var age:Int,name:String):Animal(){
constructor(age: Int):this(age,"zhangsan")
}
open class Animal(){
}
3.
interface Api{
fun a()
fun b()
}
class ApiImpl:Api{
override fun a() {
}
override fun b() {
}
}
class ApiWrapper(var api:Api):Api by api{
override fun b() {
System.currentTimeMillis()
api.b()
}
}
class Person(val name:String){
val firstName by lazy {
name.split("")[0]
}
}
4. 单例object
object Singleton{
@JvmField var x:Int=2
@JvmStatic fun y(){
}
}
Singleton.x
Singleton.y()
5.
class Outer{
inner class Inner
class StaticInner
}
val inner=Outer().Inner()
val staticInner=Outer.StaticInner()
6.
object :Cloneable,Runnable{
override fun run() {
}
}
7.
enum class Color{
White,Red,Green,Blue
}
var colorRange=Color.White..Color.Green
var color=Color.Blue
color in colorRange
8.数据类和内联类
data class Book(val id:Long,val bookName:String)
inline class BoxInt(val value:Int){
}