Scala's object-oriented collections support mutable and immutable type hierarchies. Also support functional higher-order operations such as map, filter, and reduce that let you use expression-oriented programming in collections. Higher-order operatio…
1. Translating Java Classes to Scala Classes Example 1: # a class declaration in Java public class Book{} # Scala equivalent of a class declaration class Book Example 2: # a Java class with a Construtor public class Book{ private final int isbn; priv…
1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the hierarchy and the type Nothing at the bottom of the hierarchy. All Scala types inherit from Any. # Using Any, Book extends AnyRef, and x is an Int that…
1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). example: class Shape{ def area: Double = 0.0 } # supertype # subtypes class Rectangle(val width: Double, val height: Double) extends Shape{ override def ar…
1. Variables (1) Three ways to define variables: 1) val refers to define an immutable variable; scala> val x = x: Int = scala> x*x res4: Int = scala> res4 + # use result as a value res6: Int = scala> res4 + res6 res7: Int = scala> x = # x i…
1. Functional programming treats computation as the evaluation of mathematical and avoids state and mutable data. Scala encourages an expression-oriented programming(EOP) 1) In expression-oriented programming every statement is an expression. A state…
1. Scala is a contraction of "scalable" and "language". It's a fusion of objected-oritended and functional programming. 2. Compare Book class between Java and Scala Java: class Book{ private String title; private int numberOfPages; pub…
A trait provides code reusability in Scala by encapsulating method and state and then offing possibility of mixing them into classes thus allowing code reuse. #define Trait Gliding scala> trait Gliding{ | def gliding(){ println("gliding")} |…
The basic functional cornerstones of Scala: immutable data types, passing of functions as parameters and pattern matching. 1. Basic Pattern Matching In Scala, your cases can include types, wildcards, sequences, regular expressions, and so forth. scal…
Scala进阶之路-Scala中的Ordered--Ordering 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   说道对象的比较,在Java中大家最熟悉不过的就是实现类本身实现Comparable接口或者是调用者自己实现Comparator接口均可以实现对象之间的比较.在Scala中Ordered这个特质对应的是Comparable,而Odrering这个特质对应的是Comparator.好了,废话不多说,我们直接看案例吧. 一.Java中的Comparable--Co…