在Scala程序中定义一个常量,如Pi或黄金比率,正确的做法是什么?
例如,在C#中,我可以这样做:
class Example
{
public readonly static Double GoldenRatio;
static Example ()
{
GoldenRatio = (1.0 + Math.Sqrt (5.0)) / 2.0;
}
}发布于 2014-07-18 22:00:58
它将只是一个val成员:
object Example {
val GoldenRatio = (1.0 + Math.sqrt(5.0)) / 2.0
}https://stackoverflow.com/questions/24826800
复制相似问题