-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImplicit_Demo4.scala
44 lines (32 loc) · 1.09 KB
/
Implicit_Demo4.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ScalaBasic
object Implicit_Demo4 extends App{
println("Implicit_Demo4 run ...")
implicit val myImplicitStr_1:String = "this is myImplicitStr_1"
implicit val myImplicitInt_1:Int = 123
implicit val myImplicitBoolean_1:Boolean = true
// define ur own case class
case class MyStyle(content:String)
implicit val myImplicitString:MyStyle = MyStyle("hey this is my way ~~~~")
def printImplictStr() (implicit toPrint:String): Unit = {
println("printImplict run ...")
println(toPrint)
}
def printImplictInt() (implicit toPrint:Int): Unit = {
println("printImplictInt run ...")
println(toPrint)
}
def printImplictBoolean() (implicit toPrint:Boolean): Unit = {
println("printImplictBoolean run ...")
println(toPrint)
}
def printImplictMyStyle() (implicit toPrint:MyStyle): Unit = {
println("printImplictMyStyle run ...")
println(toPrint)
println(toPrint.content)
}
// run
printImplictStr()
printImplictInt()
printImplictBoolean()
printImplictMyStyle()
}