简体   繁体   English

类型别名结构类型是什么意思?

[英]What does it mean to type alias a structural type?

I came across something like this recently我最近遇到了这样的事情

object example {
   type DButil = AnyRef {
     val a: Int
     def b: String
   }
}

Things that confused me is that usage of AnyRef here, later I dig a bit more, and I find you can also do this:让我感到困惑的是,这里使用了AnyRef ,后来我再深入一点,我发现你也可以这样做:

object apple {}
object example {
   type DButil = apple.type {
     val a: Int
     def b: String
   }
}

I've never seen this pattern before, any insights and comments are appreciated.我以前从未见过这种模式,感谢任何见解和评论。

Type alias is just an additional name to the type.类型别名只是类型的附加名称。 The constructions like AnyRef { val a: Int def b: String } apple.type { val a: Int def b: String } SomeSuperType { val structuralMember1: Int def structuralMember2: String }像 AnyRef { val a: Int def b: String } apple.type { val a: Int def b: String } SomeSuperType { val structureMember1: Int def structureMember2: String } 这样的结构

is Anonymous Class/Type that inherits superclass behavior and contains additional structural type parts that defined in braces.是继承超类行为并包含在大括号中定义的附加结构类型部分的匿名类/类型。 And type alias is just a name for that Anonymous Type.类型别名只是该匿名类型的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM