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 ...
随机推荐
- JS前端数据格式化
当我们从后台取了数据,但是我们希望在前台统一显示格式时,我们可能需要格式化数据. 今天正好总结一下前端JS格式化数据的几个方法: 1. toFixed() 方法 可把 Number 四舍五入为指定 ...
- [视频]物联网&集成系统中的物联交互、数据存储、效果展示形成快速解决方案。附:ServerSuperIO 3.6.2 版本发布。
ServerSuperIO v3.6.2版本更新内容: 设备驱动与实时库对接的Tag配置与OPC Client读取数据的配置统一用一个配置文件. 设备驱动继承DeviceDynamic接口的子类支持存 ...
- Hibernate考试试题(部分题库)含答案
Hibernate考试试题 (题库) 1. 在Hibernate中,下列说法正确的有( ABC ).[选三项] A.Hibernate是一个开放源代码的对象关系映射框架 B.Hibernate对JD ...
- Python 操作 MySQL 的正确姿势
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者:邵建永 使用Python进行MySQL的库主要有三个,Python-MySQL(更熟悉的名字可能是MyS ...
- 【外文翻译】使用Timer类去调度任务 ——java
使用Timer类去调度任务 --java 原文地址:https://dzone.com/articles/using-timer-class-to-schedule-tasks 原文作者:Jay Sr ...
- Gym - 101102C线段树
Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from t ...
- 前端框架对比之vue与regular(一)
每次一写到Regular总是忍不住先介绍一下,Regualr是网易杭州研究所的一位叫郑海波的大神写的一款前端框架,目前 这款框架推广的不深,加上其和angular过于相似的框架名,导致接受力并不大,其 ...
- js,jQuery和DOM操作的总结(一)
废话不说,直接上图 一 js的基本操作 (1)js 的六种数据类型 var n4;//六种数据类型用typeof来确定类型,Null类型的用typeof是不行的,这个是特殊 alert(typeof ...
- [js笔记整理]正则篇
一.正则基本概念 1.一种规则.模式 2.强大的字符串匹配工具 3.在js中常与字符串函数配合使用 二.js正则写法 正则在js中以正则对象存在: (1)var re=new RegExp(正则表达式 ...
- maven(02)--简单的命令操作
使用maven有什么好处呢? 这个问题留到该文的末尾进行总结>v< maven测试 在上一篇文章中介绍了如何简单的编译一个java文件,执行mvn compile命令后,你会发现在你新建的 ...