gpt4 book ai didi

scala - 特征之间的差异?

转载 作者:行者123 更新时间:2023-12-01 05:04:00 24 4
gpt4 key购买 nike

这两者有什么区别trait的?

scala> trait Bar[A <: Foo] {
| def bippy(x: A): A
| }
defined trait Bar


scala> trait BarTwo {
| type A <: Foo
|
| def bippy(x: A): A
| }
defined trait BarTwo

编辑 :

根据我的问题,它们名称的差异并不是有意义的差异。我正在寻找这两者之间的任何区别 trait结构体。

最佳答案

在大多数实际情况下,没有区别,正如@AkosKrivachy 评论的那样,它们被安排为完全等效。尽管如此,虽然the official documentation指出

it is often possible to turn abstract type members into type parameters of classes and vice versa.



最后还说

Furthermore, there are cases where it is not possible to replace abstract types with type parameters.



可悲的是,我找不到这些案例的任何描述:-(

我将此作为答案发布,以防万一可能不会出现更好的答案并且您可能想要关闭它,但让我们希望。

关于scala - 特征之间的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30760191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com