open abstract class ParentTest<in T> {标签:1.0,继承,abstract,fun,ParentTest,泛型,演示,type,hello From: https://blog.51cto.com/u_15458814/5883573
abstract fun hello(other: T): Int
}
open abstract class MyAB<T> : ParentTest<T>() {
}
class MyImp1 : MyAB<Double>() {
override fun hello(other: Double): Int {
// TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
println("hello,you call ")
return 1;
}
}
fun demo(x: ParentTest<Double>) {
x.hello(1.0) // 1.0 has type Double, which is a subtype of Number
// Thus, we can assign x to a variable of type ParentTest<Double>
val y: ParentTest<Double> = x // OK!
}
/*
fun demo1(x: ParentTest<Int>) {
x.hello(1.0) // 1.0 has type Double, which is a subtype of Number
// Thus, we can assign x to a variable of type ParentTest<Double>
val y: ParentTest<Double> = x // OK!
}
*/
demo(MyImp1());
// demo1(MyImp1());//err musct int