scala中的默认类型参数
发布时间:2020-12-16 09:06:27 所属栏目:安全 来源:网络整理
导读:我有这个特点 trait Extractor extends Mapping[Node] 什么是最简单的方法来更改它以采用默认值的类型参数 trait Extractor[T] extends Mapping[**T if given else Node**] 其他类似的问题涉及一些关于上限和下限类型的无关细节 解决方法 我想你想要将Extrac
我有这个特点
trait Extractor extends Mapping[Node] 什么是最简单的方法来更改它以采用默认值的类型参数 trait Extractor[T] extends Mapping[**T if given else Node**] 其他类似的问题涉及一些关于上限和下限类型的无关细节 解决方法
我想你想要将Extractor重载为*和善良* – > *.通常最好避免重载,所以我建议,
scala> trait Mapping[T] defined trait Mapping scala> trait Node defined trait Node scala> trait Extractor[T] extends Mapping[T] defined trait Extractor scala> type NodeExtractor = Extractor[Node] defined type alias NodeExtractor scala> val ne = new NodeExtractor {} ne: NodeExtractor = $anon$1@1ebdcc9a 如果Extractor [Node]是常见的情况,那么你可以优化它并做这样的事情, scala> trait ExtractorT[T] extends Mapping[T] defined trait ExtractorT scala> type Extractor = ExtractorT[Node] defined type alias Extractor scala> val ne = new Extractor {} ne: Extractor = $anon$1@3d70fe39 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |