package ImplicitTest
import ImplicitTest.ClothesEnum.ClothesEnum
import io.aeron.driver.cmd.CloseReceiveChannelEndpointCmd
//定义一个抽象类,里面传入的参数类型是一个泛型:类型约束
abstract class Message[T](content:T)
//继承他,然后自己的参数类型是String
class StrMessage(content:String) extends Message(content)
//继承他,然后自己的参数类型是Int
class IntMessage(content:Int) extends Message(content)
//定义了一个衣服的泛型类
class Close[A,B,C](val closeType:A,val color:B,val size:C)
//枚举类
object ClothesEnum extends Enumeration{
type ClothesEnum = Value
val 上衣,内衣,裤子 = Value
}
object ScalaFanXing {
def main(args: Array[String]): Unit = {
//三个类型
val c1 = new Close[ClothesEnum,String,Int](ClothesEnum.上衣,"black",175)
println(c1.closeType)
//与上面创建的衣服传入的三个类型不同
val c2 = new Close[ClothesEnum,String,String](ClothesEnum.内衣,"black","35c")
println(c2.color)
}
}
scala中的泛型
猜你喜欢
转载自blog.csdn.net/qq_43316411/article/details/89187614
今日推荐
周排行