Scala中的getter和setter
程序员文章站
2024-01-07 20:39:52
...
Created by Wang, Jerry, last modified on Sep 25, 2015
test source code:
/* 2015-09-14 15:36PM */
package test {
class Counter {
private var value = 0 // or else value will be treated as NaN
def add() { value += 1 } // default: public
def current = value // here I define a method without (),
// this forces the method caller to also call it without ()
def printArgs(args: Array[String]): Integer = {
args.foreach(println)
return args.length
}
var public_value = 1
}
object jerry extends App {
val counter = new Counter
println("current: " + counter.current);
val array = Array("1","2","3")
println(counter.printArgs(array))
counter.public_value = 41
println(counter.public_value)
}
}
由此可见,getter和setter并非被命名为getXXX和setXXX
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
推荐阅读
-
Scala中的getter和setter
-
再讲php中require(),include(),require_once()和include_once()他们的区别_PHP教程
-
mysql中group by和order by同时使用无效的替代方案
-
PHP.ini中配置屏蔽错误信息显示和保存错误日志的例子_PHP教程
-
mysql中的datetime和timestamp_MySQL
-
jquery中:input和input的区别分析_jquery
-
mysql中int、bigint、smallint 和 tinyint的区别与长度的含义
-
php中include,include_once和require,require_once的用法区别
-
详解Javascript中Array和Object两者之间的关系
-
实例讲解Lua中pair和ipair的区别