在一个函数体内,标识符arguments具有特殊含义. Arguments对象是一个类似数组的对象 eg: 验证函数参数的正确数目 function f(x, y, z) { if (arguments.length != 3) { throw new Error("function with " + arguments.length + "arguments, but it expects 3 arguments.") // now do the actual f…
In PHP 5.6 and later, argument lists may include the ... token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array; for example: Example #13 Using ... to access variable…
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…
笔记的整理主要针对Scala对比Java的新特性: 1.if表达式 if表达式是有结果返回的. val a= if (5>2) "你好" else 1 a的值为if表达式返回值为 "你好" 2.while表达式 while表达式是没有返回值的(返回值为 Unit),在scala中避免使用,通常都需要与var结合使用 3.for表达式 枚举集合遍历 val a = Array(1,2,3,4,5,6) for (i <- a) println(…