Scala note 1
Recently I transit to use scala to program.
scala is a functional and objected oriented language, but it has seamless java Interoperability (they both run in JVM and freely mixed).
Compared to the java that I am familiar to, there are some common concepts, data structure functions I often use in Scala,
They are also some kinds of distinctions from Java object oriented language. I put here also for quick search afterwards.
abstract final class Intobject A extends B with C {It declares an anonymous (inaccessible) class that extends both
def f(x: Any): Any = ???
}BandC, and creates a single instance of this class namedA.
Option[A] trait.Some extends Option, so it inherits everything except get and isEmpty (and some other methods implemented by a case class). Option
/ \
/ \
/ \
Some None
trait Equal {
def isEqual(x: Any): Boolean
def isNotEqual(x: Any): Boolean = !isEqual(x)
}
class Point(xc: Int, yc: Int) extends Equal {
var x: Int = xc
var y: Int = yc
def isEqual(obj: Any) = obj.isInstanceOf[Point] && obj.asInstanceOf[Point].x == y
}
(5) case class
case class Message(sender: String, recipient: String, body: String)val message1 = Message("jorge@catalonia.es", "guillaume@quebec.ca", "Com va?")copy method. You can optionally change the constructor arguments.val message2 = message1.copy(sender = message4.recipient, recipient = "claire@bourgogne.fr")Scala note 1的更多相关文章
- Spark开发环境搭建(IDEA、Scala、SVN、SBT)
软件版本 软件信息 软件名称 版本 下载地址 备注 Java 1.8 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-dow ...
- How to merge Scala Lists
Scala List FAQ: How do I merge a List in Scala? NOTE: I wrote the solutions shown below a long time ...
- Scala: Types of a higher kind
One of the more powerful features Scala has is the ability to generically abstract across things tha ...
- <译>Spark Sreaming 编程指南
Spark Streaming 编程指南 Overview A Quick Example Basic Concepts Linking Initializing StreamingContext D ...
- Beginning Scala study note(9) Scala and Java Interoperability
1. Translating Java Classes to Scala Classes Example 1: # a class declaration in Java public class B ...
- Beginning Scala study note(8) Scala Type System
1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the h ...
- Beginning Scala study note(7) Trait
A trait provides code reusability in Scala by encapsulating method and state and then offing possibi ...
- Beginning Scala study note(6) Scala Collections
Scala's object-oriented collections support mutable and immutable type hierarchies. Also support fun ...
- Beginning Scala study note(5) Pattern Matching
The basic functional cornerstones of Scala: immutable data types, passing of functions as parameters ...
随机推荐
- WebStorm设置左侧菜单栏背景和字体设置
WebStorm左侧菜单栏 webstorm是一款前端IDE利器,个人感觉黑色的背景比较炫酷,刚开始从网上下载的主题只能修改编辑窗口的背景色,经过查询资料终于把左边菜单栏的背景色也修改了. 第一步:点 ...
- myeclipse离线安装PyDev
MyEclipse装好了,用来开发java web的,一直可以用,前几天用python写爬虫,也是在myeclipse下,离线安装的包.打开后配置了一下就可以了. 这里用的是PyDev2.8.2 ...
- [C#学习]0.发表之前想说的
在这里我将学习C#编程,首先我也只是一个初学者,只是为了以后的学习,并且方便复习,所以决定在这里记录总结一些知识,简单的写一个教程.所以在这里或许难免有一些错误,欢迎大家指出,一起进步. 在这里我使用 ...
- PHP学习笔记-2
PHP 是一门弱类型语言: 在上面的实例中,我们注意到,不必向 PHP 声明该变量的数据类型.(跟Javascript很像啊!) PHP 会根据变量的值,自动把变量转换为正确的数据类型. 在强类型的编 ...
- 深入浅出node.js
http://www.infoq.com/cn/articles/what-is-nodejs/
- Spring+SpringMvc+Mybatis 框架的搭建(二)
4.4 mybatis-config.xml 这部分可以配置也可以不配置. <?xml version="1.0" encoding="UTF-8" ?& ...
- ios模拟器bug
Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Libra ...
- [笔记]机器学习(Machine Learning) - 01.线性回归(Linear Regression)
线性回归属于回归问题.对于回归问题,解决流程为: 给定数据集中每个样本及其正确答案,选择一个模型函数h(hypothesis,假设),并为h找到适应数据的(未必是全局)最优解,即找出最优解下的h的参数 ...
- Linux(ubuntu)下jdk&tomcat的安装
1.下载相应版本的jdk及tomcat:sudo wget ${url} 2.解压: tar zxvf jdk-7u79-linux-x64.tar.gz tar zxvf apache-tomca ...
- JVM调优总结:分代垃圾回收详述
为什么要分代 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大量的对象, ...