fun main() {
    var v1:Test<Int> = Test<Int>()
    v1.print(1)
    var v2:Test<String> = Test<String>()
    v2.print("fd")
}

// 模板类
class Test<T>(){
    init{
    }
    
    fun print(v:T){
        println("this is " + when(v){
            is String -> "String "
            is Int -> "Int "
            else -> "Object "
        } + " " + v)
    }
}

标签: none

评论已关闭