![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Scala
文章平均质量分 56
「已注销」
这个作者很懒,什么都没留下…
展开
-
Scala: forSome关键字
forSome是Scala的一个关键字,不是函数。在Scala的changeLog中,关于forSome的描述: “It is now possible to define existential types using the new keyword forSome. An existential type has the form T forSome {Q} where Q is a seq原创 2016-03-28 12:46:07 · 2451 阅读 · 1 评论 -
Scala函数解析
在Scala中,函数是一等公民。究竟什么是函数? 数学上我们经常这样来定义函数 : y = f(x)其中,f为函数名称,x为输入,y为输出。x输入函数f之后,经过逻辑运算得到结果y。在scala中,函数(function)实际上是Trait的一个实例。 a function that takes one argument is an instance of a Function1 tra原创 2016-03-27 20:25:22 · 670 阅读 · 0 评论 -
Scala Match
Scala中的match类似与Java中的switch case结构。在理解match之前,记住scala中,几乎一切都是表达式。匹配值 val times = 1 //> times : Int = 1 times match { case 1 => "one" case 2 => "two" ca原创 2016-03-27 20:52:08 · 881 阅读 · 0 评论 -
Scala Exception
Scala的异常通过try catch finally来处理,类似java,但是有诸多不同:try { remoteCalculatorService.add(1, 2)} catch { case e: ServerIsDownException => log.error(e, "the remote calculator service is unavailable. should h原创 2016-03-27 21:00:00 · 996 阅读 · 0 评论 -
Scala对象
Scala的世界中,对象object用于持有类的唯一对象(单例),使用object定义,常用于作为工厂或者组织静态方法。下面是一个简单的定义:object Timer { var count = 0 def currentCount(): Long = { count += 1 count }}类似与Java中的静态方法,对象中的方法直接使用对象的名称来调用:Timer.原创 2016-03-27 21:13:07 · 710 阅读 · 0 评论 -
Scala apply方法
Scala中的apply方法提供一个十分神奇有用的语法糖,诸多地方都会使用到apply方法。在类或者对象有一个很名称的用途是尤其有用。 apply methods give you a nice syntactic sugar for when a class or object has one main use.对象的apply方法: class Foo {} object FooMak原创 2016-03-27 21:25:49 · 1276 阅读 · 0 评论 -
Scala : 数据结构
List列表val nnums = List(1,2,3) //> nnums : List[Int] = List(1, 2, 3)在列表上进行map操作:nnums.map( (i : Int) => i*2) //> res0: List[Int] = List(2, 4, 6)val nnums = List(1,2,3)原创 2016-03-28 00:20:12 · 1645 阅读 · 0 评论 -
Scala : 面向表达式
Scala is highly expression-oriented: most things are expressions rather than statements.ifval color: String = if (brand == "TI") { "blue" } else if (brand == "HP") { "black" } else { "原创 2016-03-27 23:04:39 · 2154 阅读 · 0 评论 -
Scala: 类
classScala类使用class关键字定义,是对象的模板或者蓝图: class Calculator { val brand: String = "HP" def add(m: Int, n: Int): Int = m + n } val calc = new Calculator //> calc.add(3, 2)原创 2016-03-27 23:01:30 · 715 阅读 · 0 评论 -
Scala-IDE构建Maven项目
本教程演示如何使用Scala-IDE构建一个Scala Maven项目。1. 下载Scala IDE通过以下链接下载Scala IDE: http://scala-ide.org/download/sdk.html根据自己的平台选择自己相应版本下载。下载完成之后解压,如下: 选择eclipse.exe启动即可。2. 安装插件原生的Maven插件在Eclipse中,不能应用到scala项目。因此需原创 2016-03-27 14:27:39 · 5641 阅读 · 0 评论