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 = ???
}B
andC
, 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 ...
随机推荐
- JavaScript中 DOM操作方法
DM是(Document Object Model)的简称. 一.找元素 document.getElementById() 根据id选择器找,最多找一个: document.getElemen ...
- Linux防火墙配置—SNAT1
1.实验目标 以实验"防火墙配置-访问外网WEB"为基础,在WEB服务器上安装Wireshark,设置Wireshark的过滤条件为捕获HTTP报文,在Wireshark中开启捕获 ...
- Filter和Listener的应用——分IP统计网站访问次数
一:分析 统计工作需要在所有资源执行前进行,所以需要放在filter中 这个拦截器仅仅进行统计工作,不进行拦截,所以请求必须继续传递下去 用Map<String,integer>来保存数据 ...
- 内嵌的Component调用外部的方法
如果一个内嵌的Component控件需要调用外部定义的方法,用outerDocument.方法名来调用,前提是该方法是public的.如:<mx:DataGridColumn headerTex ...
- jquery中is()函数
is(expr)函数判断当前Jquery对象所匹配的元素是否存在.只要其中一种符合,就返回 true,否则返回 false. 如果 expr是个字符串,既视为Jquery的选择器,用于表示选择的元素. ...
- 蓝桥杯-大衍数列-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...
- Maven的简单搭建
Maven这个个项目管理和构建自动化工具,越来越多的开发人员使用它来管理项目中的jar包.接下来将从下面几个方向介绍maven: (1)Maven简单介绍 (2)Maven安装与配置 (3)Maven ...
- js,jQuery和DOM操作的总结(二)
jQuery的基本操作 (1)遍历键值对和数组 , , , , , ]; $.map(arr, function (ele, index) { alert(ele + '===' + index); ...
- 让Unity的Inspector面板支持字符限制(restrict)功能
今天在优化红点组件,笔者打算将红点id由10进制改为16进制处理,就打算将红点id字段由uint类型改成string类型,用于填写16进制的字符(因为在Inspector面板里,uint/int类型字 ...
- C/s从文件(TXT)中读取数据插入数据库
流程: 1.当按钮单击时,弹出OpenFileDialog 2.判断后缀名是否合法 3.导入数据库 按钮事件中的代码: 1.判断用户是否选中文件. 2.判断用户选择的文件是否为txt //第一步,当按 ...