结构类型不能包含隐式成员?

Structural types cannot contain implicit members?

不可能有像这样具有隐式成员的结构类型吗?

type Foo = { implicit val fooMsg: String }

谢谢。

即使您实际上以一种棘手的方式定义它 - 它也看不出区别:

scala> val a = new { implicit val fooMsg: String = "a" }
a: AnyRef{implicit val fooMsg: String} = $anon@7b7b04e9

scala> var b = a
b: AnyRef{implicit val fooMsg: String} = $anon@7b7b04e9

scala> b = new { implicit val fooMsg: String = "v" }
b: AnyRef{implicit val fooMsg: String} = $anon@7c8adf94

scala> b = new { val fooMsg: String = "v" }
b: AnyRef{implicit val fooMsg: String} = $anon@30cff762

scala> b = new { val fooMsgg: String = "v" }
<console>:9: error: type mismatch;
 found   : AnyRef{val fooMsgg: String; val fooMsgg: String}
 required: AnyRef{implicit val fooMsg: String}
       b = new { val fooMsgg: String = "v" }
           ^

对我来说似乎是个错误:SI-9085

这个不错。

改进仅采用声明和类型定义 --

http://www.scala-lang.org/files/archive/spec/2.11/03-types.html#compound-types

和修饰符限定模板语句中的 decl 和 def。

Refinements 显然可以覆盖(refine),但是override 也是不允许的。