zoukankan      html  css  js  c++  java
  • Scala中关于auxiliary constructors

      In Scala, constructors other than the primary constructor are called auxiliary constructors.

      Auxiliary constructors in Scala start with def this(...).

      In Scala, every auxiliary constructor must invoke another constructor of the same class as its first action. In other words, the first statement in every auxiliary

    constructor in every Scala class will have the form "this(...)". The invoked constructor is either the primary constructor (as in the Rational example), or another

    auxiliary constructor that comes textually before the calling constructor. The net effect of this rule is that every constructor invocation in Scala will end up

    eventually calling the primary constructor of the class. The primary constructor is thus the single point of entry of a class.

      Note

      If you're familiar with Java, you may wonder why Scala's rules for constructors are a bit more restrictive than Java's. In Java, a constructor must either invoke

    another constructor of the same class, or directly invoke a constructor of the superclass, as its first action. In a Scala class, only the primary constructor can

    invoke a superclass constructor. The increased restriction in Scala is really a design trade-off that needed to be paid in exchange for the greater conciseness and

    simplicity of Scala's constructors compared to Java's.

  • 相关阅读:
    [转]C# 文本框只能输入数字
    [转]C# dataGridview 报“索引-1没有值”的解决办法
    配置<authorization>节(配置文件)
    [转]javascript的urlencode
    SSM框架搭建问题
    web server
    mysql 系列
    UI 框架、ORM、权限系统
    一个基于 .NET Core 2.0 开发的简单易用的快速开发框架
    DotNetty 版 mqtt 开源客户端 (MqttFx)
  • 原文地址:https://www.cnblogs.com/25th-engineer/p/11258413.html
Copyright © 2011-2022 走看看