美文网首页kotlin
42.函数泛型

42.函数泛型

作者: 写代码的向日葵 | 来源:发表于2019-10-04 18:57 被阅读0次

    1.代码如下:

    fun main(args: Array<String>) {
        parseType(10)
        parseType("张三")
    }
    
    fun <T> parseType(thing: T) {
        when (thing) {
            is Int -> println("Int类型")
            else -> println("其它类型")
        }
    }
    

    2.输出结果如下:

    image.png

    相关文章

      网友评论

        本文标题:42.函数泛型

        本文链接:https://www.haomeiwen.com/subject/qhyspctx.html