类型别名

类型别名可以让你给已经存在的类型定义一个可选的名字。这种特性在处理泛型时非常有用,比如Collections,函数类型也是如此,同时也可以解决命名冲突

typealias OscarWinners = Map<String, String>
fun countLaLaLand(oscarWinners: OscarWinners) =
    oscarWinners.count { it.value.contains("La La Land") }
fun checkLaLaLandIsTheBestMovie(oscarWinners: Map<String, String>) =
    oscarWinners["Best picture"] == "La La Land"

results matching ""

    No results matching ""