Scala笔记:类

object test21 {

class SwingType{
def wantlearned(sw:String): Unit ={
println("兔子学会"+sw)
}
}
object swimming{
implicit def learningType(s:AnimalType)=new SwingType
}
class AnimalType
object AnimalType extends App{
import swimming._
val rabbit = new AnimalType
rabbit.wantlearned("吃苹果")
}



def main(args: Array[String]): Unit = {
val ss= SparkSession.builder().master("local[2]").appName("hello").getOrCreate()
val sc=ss.sparkContext
ss.sparkContext.setLogLevel("ERROR")

class Person[T](var name:T)
class Student[T,S](name:T,var age: S) extends Person(name)
println(new Student[String,Int]("你好",12).name)


implicit def double2Int(x:Double)=x.toInt
val x:Int=3.5


def foo(msg:String): Unit ={
println(msg)
}

implicit def intToString(x : Int) = x.toString
foo(10)





}


}
posted @ 2019-05-27 20:07  等木鱼的猫  阅读(99)  评论(0编辑  收藏  举报