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 ...
随机推荐
- 【外文翻译】 为什么我要写 getters 和setters
原文作者: Shamik Mitra 原文链接:https://dzone.com/articles/why-should-i-write-getters-and-setters 当我开始我的java ...
- linux网络编程(socket)之面向连接(TCP/IP)
1.流程 服务器: 创建socket: 绑定端口: 监听: 监听到有连接请求,接受请求: 建立连接,开始对话. 客户端: 创建socket: 请求建立连接: 连接建立成功,开始对话. 2.实例代码 / ...
- NodeJS 事件循环
Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...
- [CTSC2008] 网络管理
题目描述 Description M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个部门之间协同工作,公司搭建了一个连接整个公司的通信网络.该网络的结构 ...
- [进程管理] Linux中Load average的理解
Load average的定义 系统平均负载被定义为在特定时间间隔内运行队列中的平均进程树.如果一个进程满足以下条件则其就会位于运行队列中: - 它没有在等待I/O操作的结果 - 它没有主动进入等待状 ...
- VMWare下ubuntu无法全屏的问题解决
遇到的情况: 在VMWare中,安装ubuntu 最新版操作系统(16.04).运行该系统,发现ubuntu系统在虚拟机中,只能居中显示,全屏也只能占一半显示屏幕.怎么看,怎么不舒服. 分析问题: 一 ...
- 纯净CentOS7.2 yum源配置与使用yum 安装系统工具net-tools
本节我们来讲CentOS 的yum 源配置 一.yum 简介 yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器 ...
- spring计划任务
Spring3中加强了注解的使用,其中计划任务也得到了增强,现在创建一个计划任务只需要两步就完成了: 创建一个Java类,添加一个无参无返回值的方法,在方法上用@Scheduled注解修饰一下: 在S ...
- 解析Excel文件并把数据存入数据库
前段时间做一个小项目,为了同时存储多条数据,其中有一个功能是解析Excel并把其中的数据存入对应数据库中.花了两天时间,不过一天多是因为用了"upload"关键字作为URL从而导致 ...
- struts2总体介绍
这篇博客开始将总结一下有关框架的知识,在开发中合适的利用框架会使我们的开发效率大大提高.当今比较流行的开源框架: 关注数据流程的MVC框架 (Struts1/2, WebWork, Spring MV ...