标签:boolean pointer singleton define uil ini sign pretty uid
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 { def f(x: Any): Any = ??? }
It declares an anonymous (inaccessible) class that extends bothBandC, 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")标签:boolean pointer singleton define uil ini sign pretty uid
原文地址:http://www.cnblogs.com/anxin6699/p/6984158.html