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 t1

Here 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 -> Any

Here 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的特征线性化相关推荐

  1. scala特质_Scala的特质

    scala特质 Scala特质 (Scala traits) Traits in Scala are like interfaces in Java. A trait can have fields ...

  2. scala 单元测试_Scala中的法律测试简介

    scala 单元测试 Property-based law testing is one of the most powerful tools in the scala ecosystem. In t ...

  3. scala特性_Scala | 特性应用

    scala特性 特性应用 (Trait App) Scala uses a trait called "App" which is used to convert objects ...

  4. scala运算符_Scala的所有符号运算符是什么意思?

    scala运算符 Scala的符号运算符 (Scala's symbolic operators) The symbolic operators in Scala are symbols that h ...

  5. scala 抽象方法_Scala抽象类型

    scala 抽象方法 The type whose identity is not known precisely can be termed as abstract type. 身份未知的类型可以称 ...

  6. scala设计模式_Scala中的工厂设计模式

    scala设计模式 I'm going to deliver a series of Scala Design Patterns in my coming posts. I will pick-up ...

  7. scala编程_Scala编程语言简介

    scala编程 Scala is a programming language that integrates the object oriented and functional language ...

  8. scala案例_Scala案例类和案例对象深入(第2部分)

    scala案例 发表简短目录 (Post Brief TOC) Introduction介绍 Scala's Case Class Benefit-6Scala案例类权益6 Advantages of ...

  9. scala特性_Scala特性示例教程

    scala特性 Scala Traits consists of method and field definitions that can be reused by mixing classes. ...

最新文章

  1. python提示keyerror 13372,Python 学习笔记之—— Pandas 库
  2. 从注册流程 分析如何安全退出多个Activity 多种方式(附DEMO)
  3. 进程间通信——匿名管道
  4. Selenium2+python自动化58-读取Excel数据(xlrd)
  5. SharePoint PowerShell 修改母版页
  6. 这篇Redis文章,图灵看了都说好
  7. CF924D. Contact ATC
  8. DotNet Core 2.0部署后外网IP访问
  9. winpcapp配置c++网口通讯_PLC通讯智能网关,不用编程,实现西门子与罗克韦尔(AB)、三菱等PLC之间通讯...
  10. 计算机系徽文案例,信息技术系——系徽征集令,重磅发布!
  11. 算法题9-最短路径问题-Dijkstra算法
  12. LZW编码算法原理及实例应用
  13. 咱张家界桑植的野外小吃
  14. 需求工程-学习通习题-太原理工大学(14-17章)
  15. 2021贵港市地区高考成绩排名查询,贵港高中成绩排名2021,贵港中考分数线排行榜...
  16. 如何做好跨境电商店铺定位—扬帆牧哲
  17. idea Compound 一次启动多个应用
  18. R语言绘图基础学习(一)
  19. 基于MPLS ×××城域网设计
  20. 带你了解不一样的sDNA

热门文章

  1. vim配置之spacevim
  2. stn算子_深度学习常用算子(二)
  3. fastexcel读取excel追加写入sheet页_python笔记52:python操作excel
  4. html jq 控制显示密码,js、jquery分别实现点击密码输入框密码显示和隐藏
  5. java匿名对象 回收_Java 匿名对象
  6. python判断正确错误_python错误和异常
  7. 16张图带你吃透高性能 Redis 集群
  8. 12-容器之间link
  9. linux I/O 栈 预习(上)
  10. 《程序设计与数据结构》第八周学习总结