如何在Scala中修复此类型不匹配错误?
发布时间:2020-12-16 18:20:53 所属栏目:安全 来源:网络整理
导读:我在 Scala REPL中收到以下错误: scala trait Foo[T] { def foo[T]:T }defined trait Fooscala object FooInt extends Foo[Int] { def foo[Int] = 0 }console:8: error: type mismatch;found : scala.Int(0)required: Int object FooInt extends Foo[Int] {
我在
Scala REPL中收到以下错误:
scala> trait Foo[T] { def foo[T]:T } defined trait Foo scala> object FooInt extends Foo[Int] { def foo[Int] = 0 } <console>:8: error: type mismatch; found : scala.Int(0) required: Int object FooInt extends Foo[Int] { def foo[Int] = 0 } ^ 我想知道它究竟意味着什么,以及如何解决它. 解决方法
您可能在方法foo上不需要该类型参数.问题是它影响了它的特性Foo的类型参数,但它不一样.
object FooInt extends Foo[Int] { def foo[Int] = 0 // ^ This is a type parameter named Int,not Int the class. } 同样, trait Foo[T] { def foo[T]: T } ^ not the ^ same T 你应该删除它: trait Foo[T] { def foo: T } object FooInt extends Foo[Int] { def foo = 0 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Angular – 读取文件并解析其内容
- Scala函数使用泛型函数的映射对Seq进行排序
- The Best BootStrap Resources
- 如何在bash上运行mysql命令?
- 在Scala中自定义“let”表达式
- angularjs – 使用Firefox或Safari在量角器中进行E2E测试?
- angularjs – NodeJS:在客户端存储JWT的位置? sessionSto
- 3款强大的BootStrap的可视化制作工具推荐
- twitter-bootstrap – 集成bootstrap-select以与Ember一起使
- angularjs – 使用jasmine测试角度工厂时出现未知的提供程序