Scala的隐式对象

复制代码
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
  }
}
相关推荐
AI逐月1 小时前
解决 ComfyUI 插件安装后 Nanobind 报错问题:soxr 版本冲突原理解读
开发语言·python
清华都得不到的好学生1 小时前
数据结构->1.稀疏数组,2.数组队列(没有取模),3.环形队列
java·开发语言·数据结构
光影少年1 小时前
数组去重方法
开发语言·前端·javascript
我命由我123451 小时前
浏览器的 JS 模块化支持观察记录
开发语言·前端·javascript·css·html·ecmascript·html5
软件开发技术深度爱好者1 小时前
用python + pillow实现GUI界面图片GUI处理工具
开发语言·python
weixin_425023001 小时前
PG JSONB 对应 Java 字段 + MyBatis-Plus 完整实战
java·开发语言·mybatis
leaves falling2 小时前
C++ string 类:从入门到模拟实现
开发语言·c++
智算菩萨2 小时前
【Tkinter】15 样式与主题深度解析:ttk 主题系统、Style 对象与跨平台样式管理实战
开发语言·python·ui·ai编程·tkinter
子非鱼@Itfuture2 小时前
`<T> T execute(...)` 泛型方法 VS `TaskExecutor<T>` 泛型接口对比分析
java·开发语言
weixin_419349792 小时前
Python 项目中生成 requirements.txt 文件
开发语言·python