Scala
scala语言的学习之旅
DearNingning
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
泛型的定义和上下界
class Demo001[K,V] { def show(k:K,v:V)={ println(s"$k $v") } } object Demo001{ def main(args: Array[String]): Unit = { val demo=new Demo001[Int,String] demo.show(1,"cc") val demo2=new Demo001[Int,Int] demo2.show(10,20) } } cl原创 2021-06-09 23:00:54 · 156 阅读 · 0 评论 -
自定义排序
object Text01 { def main(args: Array[String]): Unit = { val ls=List(new User(1,"WNN",10),new User(2,"CC",11),new User(3,"DD",19)) implicit def opt(user: User): Ordered[User] ={ new Ordered[User] { override def compare(that: User): I原创 2021-06-09 22:50:16 · 119 阅读 · 0 评论 -
隐式函数、隐式类
隐式函数 object ImpliDemo { implicit val age:Int =100 def opt(x:Int,y:Int)(implicit f:(Int,Int)=>Int)={ f(x,y) } def opt1(x:Int,y:Int)(implicit f:(Int,Int)=>Int)={ f(x,y) } def main(args: Array[String]): Unit = { // implicit原创 2021-06-09 22:12:33 · 288 阅读 · 0 评论 -
scala之匹配模式
object Demo03 { def main(args: Array[String]): Unit = { val ls=List(1,2,3,"a","b","c",10.11,12.12,13.13) /*val res: List[Any] = ls.map(e=>{ if(e.isInstanceOf[Int]){ e.asInstanceOf[Int]*10 }else if(e.isInstanceOf[String]){原创 2021-06-07 23:12:44 · 129 阅读 · 0 评论 -
偏函数及其简写形式
object PartFun { def main(args: Array[String]): Unit = { val ls: List[Any] = List("wnn","a","b",1,2,3,10.0,11.0,true) val f: PartialFunction[Any, Int] =new PartialFunction[Any,Int] { override def isDefinedAt(x: Any): Boolean = { x.is原创 2021-06-07 22:02:53 · 207 阅读 · 0 评论 -
scala之高阶函数
object HanShu { def opt(x:Int,y:Int,f:(Int,Int)=>Int)={ f(x,y) } def main(args: Array[String]): Unit = { println(opt(1, 3, (x1, x2) => x1 + x2)) println(opt(1, 3, (x1, x2) => x1 * x2)) } } object HanShu2 { def opt(x:String,原创 2021-06-06 21:59:44 · 107 阅读 · 0 评论 -
特质动态混入
class Demo01 extends T1 with T2 with T3{ override def t11: Unit = { println("快捷键不会有t11") } def t1: Unit = { println("快捷键会有t1") } override def t2: Unit = { println("重写了t2") } override def t3: Unit = { println("重写了t3")原创 2021-06-06 19:57:22 · 331 阅读 · 0 评论 -
scala特质
trait Tdemo01 { def add2(x:Int,y:Int):Int def show2 } trait Tdemo { def add(x:Int,y:Int):Int def show } import day03.Tdemo /** * Author Ning.W * Date: 2021/6/5 * Description: */ class TraitDemo01 extends Tdemo with Tdemo01{ override def show:原创 2021-06-05 22:50:03 · 116 阅读 · 0 评论 -
scala之apply方法
object ApplyDemo { def apply(): ApplyDemo = new ApplyDemo() def main(args: Array[String]): Unit = { val demo: ApplyDemo =new ApplyDemo // demo.show ApplyDemo.apply().show } } class ApplyDemo{ def show={ println("ccccc") } } obje原创 2021-06-04 23:02:12 · 130 阅读 · 0 评论 -
scala之代码块
原创 2021-06-04 22:09:00 · 237 阅读 · 0 评论 -
scala主构造器和辅助构造器
主构造器和辅助构造器 class User(var id:Int,var name:String) { var sal: Double= _ def this()={ this(2,"cc") } def this(sal:Double){ this() this.sal=sal } override def toString: String = s"id = $id; name= $name" } object Demo05 { def main原创 2021-06-03 22:18:49 · 138 阅读 · 0 评论 -
scala半生类和半生对象
原创 2021-06-03 20:23:08 · 295 阅读 · 0 评论 -
scala 进阶篇
object SliceDemo { def main(args: Array[String]): Unit = { val arr: Array[String] =Array("wnn","cc","xx","dh","asd") val ls: List[String] =arr.toList // println(ls) val res: Array[String] =arr.slice(0,3) //println(res.toList) val s原创 2021-06-01 23:23:40 · 172 阅读 · 0 评论 -
Scala之进阶篇
object ZipDemo { def main(args: Array[String]): Unit = { val arr: Array[String] =Array("wnn","lcc","hxx") val arr1: Array[Int] =Array(1,2,3) val res: Array[(String, Int)] = arr.zip(arr1) //第一种方式 res.foreach(println) //第二种方式 val原创 2021-06-01 22:04:27 · 116 阅读 · 0 评论 -
大数据之Scala
scala底层就是java;spark底层是scala写的 object Demo12 { def main(args: Array[String]): Unit = { println("aa") } } /* * object是静态的 * 里面的mian方法也是静态的 * extends App 里面可以不写main方法 * */ object Demo11 extends App { println("wnn") } //变量的定义,不初始化赋值会报错 var ag.原创 2021-05-24 22:28:23 · 176 阅读 · 1 评论
分享