//类似 构造函数 2
import ceylon.math.float { sin, cos }
import java.lang { Runtime }
class Counter(angle,radius,String? label) {
shared Float angle;
shared Float radius;
shared Float x => radius * cos(angle);
shared Float y => radius * sin(angle);
//返回 此方法返回到虚拟机的最大可用的处理器数量;决不会小于一个
shared Integer procs = Runtime.runtime.availableProcessors();
// 计数器
variable Integer count = 0;
shared Integer inc() => ++count;
shared variable Float allresult = 0.0;
allresult = angle*radius;
shared String description {
if (exists label) {
return label;
}
else {
return "(``radius``,``angle``,``allresult``,``x``,``y``,``procs``)";
}
}
//get set 使用
// way 1
variable String _name = "";
shared String name => _name; //pointless getter
assign name => _name=name;//pointless setter
// way 2
variable String nickname = "";
shared void setNickNamen(String nickname)
{
this.nickname = nickname;
}
shared String getNickName()
{
return this.nickname;
}
// end get set
}
ceylon 学习4 set get 优化
最新推荐文章于 2023-09-11 09:57:20 发布