![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Scala
码上行动、
这个作者很懒,什么都没留下…
展开
-
Scala中的apply()方法和unapply()方法的使用
apply()的使用,apply⽅法⼀般都声明在伴⽣类对象中,可以⽤来实例化伴⽣类的对象 unapply()的使用,也被称为提取器 object Hello { def main(args: Array[String]): Unit = { val test0 = new Test02("goudan") val test01 = Test02("goduan") val goudan = new Test02("狗蛋", 19) /.原创 2021-08-05 21:31:13 · 370 阅读 · 0 评论 -
Scala中的对象丶构造器丶单例对象是使用方法
Scala中自定义get和set方法 object Test07 { def main(args: Array[String]): Unit = { val person = new Test07 person.name_:("goudan") println(person.name) person.setAge(18) println(person.getAge) } } class Test07{ .原创 2021-08-05 20:51:33 · 159 阅读 · 0 评论 -
Scala中的模式匹配
match case的语法如下 变量 match { case 值 = > 代码} 值匹配 1.scala中的模式匹配只会匹配到一个分支,不需要使用break语句 2.match是表达式,与if表达式一样是有值的 3.除了可以匹配常量,还可以匹配变量 4.支持模式守卫 val ch: Char = 'e' ch match { case 'c' | 'C' => print ("这是c") //添加模式守卫 case _ if ch>'c' => print ("这是其他.原创 2021-08-05 15:59:11 · 114 阅读 · 0 评论