区分args(Argument)【引数】与 parm(Parameter)【参数】
首先引用一段英文介绍
An argument is an expression used when calling the method.
A parameter is the variable which is part of the method’s signature (method declaration).
--选自 stackoverflow
看过的一些文章和书籍较少对这两个名称做限定,一般都翻译为或者读作 ‘参数’,但是在使用和写文档时候还是要加以区分才让人好理解。
台湾版的翻译中,翻译 args为引数,param为参数。光听名称也是不好理解,我下面写一个例子来清晰表示。
- /**
- * Description: Args and Param Comparision
- * author: J.K.alex
- * Date: Created in 13:45 2020/2/27
- */
- class Student(age: Int, name: String) {
- /** 这里的name 、 age 是args(arguments) */
- def this(name: String, age: Int) = {
- this(age, name)
- println(s"This is $name ,his/her age is $age")
- }
- println(s"Age is $age ,his/her name is $name")
- }
- object Demo {
- def main(args: Array[String]): Unit = {
- /** 这里传入的 25 \ alex 是 param(parameters) */
- val student = new Student(25, "alex")
- }
- }