<>scala样例类
代码
//样例类 object CaseDemo { def main(args: Array[String]): Unit = { //定义样例类
//构造函数的参数默认是public case class Message( var sender:String,recipient:String ,body:
String) //创建样例类的对象 val messagel=Message("Jerry","Tom","Hello") println("sender:"
+messagel.sender) println("recipient:"+messagel.recipient) messagel.sender="Bob"
//sender使用var修饰时可以输出 println("sender2:"+messagel.sender)
//messagel.recipient="sss"//recipient默认使用val修饰 } }
结果
sender:Jerry recipient:Tom sender2:Bob Process finished with exit code 0