问题标签 [scala-2.12]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
83 浏览

scala - Scala - 覆盖抽象方法的类型类

我在 scala 2.12 上有点挣扎:

我有以下层次结构:

效果很好。但我想为 writer 提供一个替代实现:

但我明白了object creation impossible, since method write in trait Writer of type (config: Playground.A)Unit is not defined

我假设由于 B 是 A,这应该有效。如何使用wherewrite类型的配置覆盖BB <: A

斯卡斯蒂:https ://scastie.scala-lang.org/QBaiiDP4Sj2lptUjrWLJYw

编辑: - - - - - - - - - - - - - - - - - - - - - - - - ------------

根据一些输入,我将实现更改为:

哪个有效。

但是,如果我修改它以访问 中的变量config,它会中断:

value format is not a member of type parameter B

https://scastie.scala-lang.org/Xj2rKbbiTmG7raZgQZYfHA

欣赏输入。