scala 线性回归_Scala的特征线性化
scala 線性回歸
Scala | 特性線性化 (Scala | Trait Linearization)
In Scala programming language, trait linearization is a property that helps to rectify ambiguity when instances of a class that are defined using multiple inheritances from different classes and traits are created.?
在Scala編程語言中, 特征線性化是一種屬性,當創建使用來自不同類和特征的多個繼承定義的類的實例時,該屬性有助于糾正歧義。
It resolves ambiguity that may arise when class or trait inherits property from 2 different parents (they may be classes or traits).
它解決了當類或特征從2個不同的父代(它們可能是類或特征 )繼承財產時可能出現的歧義。
Syntax:
句法:
trait t1{} class c1{} class main{} object obj1 = new class main extents c1 with t1Here linearization will make the inheritance structure clear so that no problem could arise in the future.
在這里線性化將使繼承結構清晰明了,以便將來不會出現任何問題。
Here, we will consider two root classes, AnyRef root for all reference types. Any root for all classes in Scala.
在這里,我們將考慮兩個根類, 即所有引用類型的AnyRef根。 Scala中所有類的任何根。
線性化 (Linearization)
t1 -> AnyRef -> Any c1 -> AnyRef -> Any main -> AnyRef -> Any obj1 -> main -> t1 -> c1 -> AnyRef -> AnyHere the linearization will go in the following order: main class -> t1 trait -> c1 class -> AnyRef -> Any
這里線性化將按照以下順序進行: 主類-> t1特征-> c1類-> AnyRef-> Any
This sample program will make the concept more clear,
該示例程序將使概念更清晰,
class vehicle { def method: String= "vehicle " } trait bike extends vehicle { override def method: String = "Bike-> "+ super.method } trait muscleBike extends vehicle { override def method: String = "Muscle Bike -> "+ super.method } trait harley extends vehicle { override def method: String ="Harley Davidson-> "+ super.method } class iron extends bike with muscleBike with harley { override def method: String = "Iron 833 -> "+ super.method } object myObject { def main(args: Array[String]) { var myBike = new iron println(myBike.method) } }Output
輸出量
Iron 833 -> Harley Davidson-> Muscle Bike -> Bike-> vehicle特征線性化的特征 (Features of trait linearization)
It is used to solve ambiguity in Scala which arises in the case of multiple inheritances.
它用于解決Scala中的多重繼承時出現的歧義。
The calling of a super method by subclasses is managed using stack.
子類對super方法的調用是使用堆棧管理的。
Linearization comes into play when a new class instance is created.
當創建一個新的類實例時,線性化就起作用了。
Linearization may not be the same as inherited mixins because mixins are defined by the programmer.
線性化可能與繼承的mixin不同,因為mixin由程序員定義。
Linearization avoids repeated inheritance and if we explicitly try to add a class to inheritance an error will be thrown.
線性化避免了重復的繼承,如果我們顯式地嘗試向繼承中添加類,則會拋出錯誤。
翻譯自: https://www.includehelp.com/scala/trait-linearization.aspx
scala 線性回歸
總結
以上是生活随笔為你收集整理的scala 线性回归_Scala的特征线性化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哈希表的最差复杂度是n2_给定数组A [
- 下一篇: [转载] Python3.0中普通方法、