Create Me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Learn Scala in one minutes
case class AboutMe(name: String = "zqh", nickName: String = "zqhxuyuan") {

def hello() = s"hello $name."

val family = List[String]("Wife", "Daughter", "Son")
val livings = mutable.ListBuffer[String]("Putian", "Shanghai", "Hangzhou")

val hobbies: java.util.List[String] = new java.util.ArrayList[String]()

def hobby(name: String): Boolean = hobbies.add(name)

def state(): Map[State, Any] = {
val stating = mutable.Map[State, Any]()
stating += Born -> livings.head
stating += Work -> livings.last
val pass = livings - livings.head - livings.last
stating += Pass -> pass.toList
stating.toMap
}
}

Describe me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sealed trait State
case object Born extends State
case object Work extends State
case object Pass extends State

object AboutMe extends App {
val me = AboutMe()

def printMe(): Unit = {
println(me.hello())
println(s"Family:${me.family.mkString(",")}")
println(s"Living:${me.livings.toList.mkString(",")}")
me.state().foreach(println)
me.hobby("Coding...")
println("hobby:" + me.hobbies.asScala.mkString(","))
}
}