当前位置:网站首页>Scala sample class

Scala sample class

2022-06-25 01:03:00 Jue Niu thunder plough hot blade

//  Sample class 
// Scala in , The sample class is a special class , It is generally used to save data ( Be similar to Java Bean), In concurrent programming and Spark、Flink It is often used in these frameworks 
//  Format 
// case class  Sample class name ([var/val]  Member variable name 1: type 1,  Member variables 2: type 2,  Member variable name 3: type 3){}
//
//  If you don't write , The default modifier of the variable is val, namely val Omission 
//  If you want to implement a member variable, the value can be modified , You need to add it manually var To modify variables 
object  Sample class  {
    

  case class Person(name: String = " Zhang San ", var age: Int = 10) {
    }

  def main(args: Array[String]): Unit = {
    
    val p = Person()
    println(s" Before the change :name = ${p.name}, age = ${p.age}")
    // p.name="" //  Report errors , The default modifier without is val, Do not modify the 
    p.age = 18
    println(s" After modification :name = ${p.name}, age = ${p.age}")
  }

}
原网站

版权声明
本文为[Jue Niu thunder plough hot blade]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210544013881.html