kotlin日常
泛型
class TypedClass<T>(parameter: T) {
val value: T = parameter
}
val t1 = TypedClass<String>("Hello World!")
val t2 = TypedClass<Int>(25)
//简写
val t1 = TypedClass("Hello World!")
val t2 = TypedClass(25)
val t3 = TypedClass<String?>(null)
//非空
class TypedClass<T : Any>(parameter: T) {
val value: T = parameter
}
//Context
class TypedClass<T : Context>(parameter: T) {
val value: T = parameter
}
Over 哒哒哒啦 哒哒哒啦 哒哒哒哒哒啦

网友评论