隐式参数
This commit is contained in:
22
src/main/scala/top/fjy8018/scala/ImplicitParaApp.scala
Normal file
22
src/main/scala/top/fjy8018/scala/ImplicitParaApp.scala
Normal file
@@ -0,0 +1,22 @@
|
||||
package top.fjy8018.scala
|
||||
|
||||
/**
|
||||
* F嘉阳
|
||||
* 2019-01-03 11:32
|
||||
*/
|
||||
object ImplicitParaApp {
|
||||
|
||||
implicit val test = "test"
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
// 隐式参数会自动寻找方法、类内部、伴生类内类型匹配的唯一参数
|
||||
// 若外部定义了多个隐式参数则报错
|
||||
def testPara(implicit name: String): Unit = {
|
||||
println(name + "...")
|
||||
}
|
||||
|
||||
testPara
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user