scala 辅助构造函数_Scala辅助构造函数的深入介绍

scala 辅助构造函数

Before reading this post, please read my previous post about “Scala Primary Constructor In-Depth”.

在阅读这篇文章之前,请阅读我之前关于“ Scala Primary Constructor Inpth”的文章

发表简短目录 (Post Brief TOC)

  • Introduction

    介绍
  • What is an Auxiliary Constructor?

    什么是辅助构造函数?
  • Auxiliary Constructor Advantages and Disadvantages

    辅助构造函数的优缺点
  • Scala Auxiliary Constructor Examples

    Scala辅助构造函数示例
  • Scala Auxiliary Constructor Rules

    Scala辅助构造函数规则
  • Constructor Overloading With Auxiliary constructors

    辅助构造函数的构造函数重载

介绍 (Introduction)

A Scala class can contain two kinds of constructors:

Scala类可以包含两种构造函数:

  • Primary Constructor

    主要建设者
  • Auxiliary Constructor

    辅助构造器

We have already discussed about Primary Constructor in my previous post. In this post, we are going to discuss about Auxiliary Constructors in-depth with suitable examples.

在我以前的文章中,我们已经讨论了有关Primary Constructor的问题。 在本文中,我们将通过适当的示例深入讨论辅助构造函数。

什么是辅助构造函数? (What is an Auxiliary Constructor?)

In Scala, We can define Auxiliary Constructors like methods by using “def” and “this” keywords. “this” is the constructor name.

在Scala中,我们可以使用“ def”和“ this”关键字来定义类似于方法的辅助构造函数。 “ this”是构造函数名称。

Auxiliary Constructor is also know as Secondary Constructor. A Scala class can contain zero or one or more Auxiliary Constructors.

辅助构造函数也称为辅助构造函数。 Scala类可以包含零个或一个或多个辅助构造函数。

辅助构造方法的优缺点 (Auxiliary Constructor Advantage and Disadvantage)

What is the main Advantage of Auxiliary Constructors in Scala?
In Scala, Auxiliary Constructors are used to provide Constructors Overloading.

Scala辅助构造函数的主要优点是什么?
在Scala中,辅助构造函数用于提供构造函数重载。

What is the main Disadvantage of Auxiliary Constructors in Scala?
We need to write lot of code to provide Constructors Overloading using Auxil

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值