协变 逆变
object Test6 {
class Ye{
def tra()={
println("我是爷")
}
}
class Die extends Ye {
override def tra(): Unit = {
println("我是爹")
}
}
class Er extends Die {
override def tra(): Unit = {
println("我是儿")
}
}
class jia[+T]//协变
class jian[-T]//逆变
def main(args: Array[String]): Unit = {
val die = new Die
val value:jia[Ye] = new jia[Die]
val value1:jian[Er] = new jian[Die]
fun(die).tra()
}
def fun:PartialFunction[Die,Die]={
case a:Die => new Er
}
}
val value:协变类[输入类型及其父类]=new 协变类[输入类型]
val value:协变类[输入类型及其子类]=new 逆变类[输入类型]
泛型[-类型1,+类型2]
参数->(类型1及其父类,类型2及其子类)