package hfd
//隐式对象
//implicit object
//作用:给函数的隐式参数提供默认值
object Test38_4 {
case class DatabaseConfig(driver:String,url:String)
//座位含税的隐式参数的默认值
implicit object MySqlDefault extends DatabaseConfig("mysql","localhost:443")
def getConn(implicit config: DatabaseConfig):Unit={
println(config)
}
def main(args: Array[String]): Unit = {
//getConn(DatabaseConfig("sqlite","localhost:80"))
getConn
}
}
Scala的隐式对象
2401_833788052024-12-13 19:42
相关推荐
014-code1 天前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)lly2024061 天前
组合模式(Composite Pattern)游乐码1 天前
c#泛型约束Dontla1 天前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)chushiyunen1 天前
python rest请求、requests铁东博客1 天前
Go实现周易大衍筮法三变取爻baidu_huihui1 天前
在 CentOS 9 上安装 pip(Python 的包管理工具)南 阳1 天前
Python从入门到精通day63lbb 小魔仙1 天前
Python_RAG知识库问答系统实战指南551只玄猫1 天前
【数学建模 matlab 实验报告13】主成分分析