在Scala程序中定义常数(例如Pi或黄金比例)是正确的吗?
例如,在C#中,我可以这样做:
class Example
{
public readonly static Double GoldenRatio;
static Example ()
{
GoldenRatio = (1.0 + Math.Sqrt (5.0)) / 2.0;
}
}
它只是一个val
成员:
object Example {
val GoldenRatio = (1.0 + Math.sqrt(5.0)) / 2.0
}
另外,请查看有关常量的《Scala样式指南》部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句