1. 泛型类
class Test1[T](val p1: T){
def t1():Unit = {
println("there is " + p1)
}
}
object Test {
def main(args: Array[String]): Unit = {
val t1 = new Test1("haha")
t1.t1()
}
}
在构造的Test1 类的时候, 传入一个参数,类型任意
2. 泛型方法
class Test1[T](val p1: T){
def t1[T](p2: T):Unit = {// 泛型方法
println("there is " + p1 + p2)
}
}
object Test {
def main(args: Array[String]): Unit = {
val t1 = new Test1("haha")
t1.t1("haha2")
}
}
3. 类型变量限定
[A <: B] : A 必须是B的子类
[A >: B] : A 必须是B的父类
[A <% B]: A 可以隐式转换为B
4. 多重限定
5. 协变