kotlin 系统类型

  

泛型

变量类型的参数化

1.最基本泛型

fun main() {
    var a: A<String> = A<String>("hello")
    a.test()
    //简写,可以不使用<>
    var b = A("hello")
    b.test()

}

data class A<T>(var t:T){
    fun test(){
        println(t)
    }
}

猜你喜欢

转载自www.cnblogs.com/buchizaodian/p/12630259.html
今日推荐