def method1(x: Int, y: Int): Int = {
def description = name + " is " + age + " years old with " + prop.toBuffer
def getSession(): Session ={
val method2 = (x: Float, y: Float) => x * y
println(method2(3.2f,2.0f))
val func = (x: Int, y: Int) => x * y
def method1(fun: (Int, Int) => Int): Int = {
val a =new Array[Int](10)
val b =new ArrayBuffer[Int](10)
val a = ArrayBuffer[Float](2.0f, 3.2f, 4.5f)
for (i <- (0 until a.length).reverse) {
val a = Array[String]("nima","shabi","hehe")
val name =a(Random.nextInt(a.length))
case "nima" => println("1,nima")
case "shabi" => println("2.shabi")
case _ => println("3,hehe")
case x: Int => println("Int " + x)
case y: Double if(y >= 0) => println("Double "+ y)
case z: String => println("String " + z)
case _ => throw new Exception("not match exception")
…………………………列表 List………………………………
a :: list ; a +: list ; lst3 = lst1.::(0) ; lst5 = lst1.+:(0)
…………………………集合 Set…………………………………
val set1 = new HashSet[Int]()
val set3 = set1 ++ Set(5, 6, 7)
val set0 = Set(1,3,4) ++ set1
……………………………Map 集合………………………………………
val map1 = new mutable.HashMap[String, Int]()
class Person(val name: String, val age: Int) {
def this(name: String, age: Int, gender: String) {
def main(args: Array[String]): Unit = {
val p1 = new Person("shabi", 23,"female")
println(p1.name+p1.age+p1.gender)
class Person(name: String, age: Int) {
private var gender = "male"
def printPerson: Unit = {
println(this.id + " " + this.gender + " " + this.name + " " + this.age + " " + Person.a)
def apply(name: String, age: Int): Person = new Person(name, age)
def main(args: Array[String]): Unit = {
val p1 = Person.apply("曾祥雨",23)
case class SubmitTask(id: String, name: String)
case class HeartBeat(time: Long)
case object CheckTimeOutTask
object CaseDemo04 extends App{
val arr = Array(CheckTimeOutTask, HeartBeat(12333), SubmitTask("0001", "task-0001"))
arr(Random.nextInt(arr.length)) match {
case SubmitTask(id, name) => {println(s"$id, $name")
case HeartBeat(time) => {println(time)}
case CheckTimeOutTask => {println("check")}
val fun1 = (x:Int) => x*x
arr.map( (x:Int) = >x*x )
new_list = list.map((x: Int) => x * 3)
new_list = list.map((x) => x * 3)
new_list = list.map(x => x * 3)
new_list = list.map(_ * 3)
new_list.foreach(println(_))
def m(x:Int)=(y:Int)=>x*y
def sayHi()(implicit name :String="aaa"): Unit ={
def main(args: Array[String]): Unit = {