scala – 列出所有可见的含义
发布时间:2020-12-16 18:30:26 所属栏目:安全 来源:网络整理
导读:如果可能的话,如何使用反射和宏列出所有可见的含义?我需要这个能够分析可用的类型类实例. 用例 case class Artist (name: String,genres: Set[Genre])case class Genre (name: String)object CatalogueDB extends MySQL { implicit val artistEntity = new
如果可能的话,如何使用反射和宏列出所有可见的含义?我需要这个能够分析可用的类型类实例.
用例 case class Artist (name: String,genres: Set[Genre]) case class Genre (name: String) object CatalogueDB extends MySQL { implicit val artistEntity = new Entity[Artist] {...} implicit val genreEntity = new Entity[Genre] {...} } trait MySQL { // Typeclasses let me restrict methods on `MySQL` to work only for types,// which are associated with its instance. // E.g.,the following method will only compile when either an `Artist` or // a `Genre` is passed to it when called on `CatalogueDB`: def save[e : Entity](e : e) ... // But also I need to be able to get a list of those types and // instances of `Entity` typeclass to get the information // needed to generate the database schema and // to perform other tasks like that. // So,the following method should somehow be able to have // the `Entity` instances for `Artist` and `Genre` at its disposal,// when called on `CatalogueDB`. def generateSchema ... } 解决方法
我认为目前还没有办法做到这一点.但是,列出给定类的所有成员并检查它们是否是隐式的应该相对容易 – 无论是在编译时还是在运行时.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 使用angular2 自带的指令,快捷创建服务,组件等!
- 用shell写一个服务启动脚本,速度get!
- 类型参数中的Scala类型级别标识函数
- 12306NG 开源项目群定义与发展建议
- scala – 是否可以更新实现共同特征的任何案例类的字段
- 在运行测试之前,AngularJS Protractor等待所有ajax调用结束
- bash – 如何减少ssh连接超时值
- WebService异常Unexpected wrapper element ... found. Exp
- twitter-bootstrap – Bootstrap 4 Beta – 是否需要Popper
- bash – 当没有添加目录或文件时grep会做什么