是否可以在 Scala Trait 中声明静态变量和函数?
Is it possible to declare static vaiables and functions in a Scala Trait?
我知道可以在 Scala 中使用伴随对象为 Class 声明静态变量和函数,但是有没有办法在 Trait 中声明静态 variables/funcions?
您可以为 trait
设置伴生对象,就像为 class
设置伴生对象一样。
所以你不能在 trait
中声明 static
值,因为 Scala 不那样工作,但你可以使用伴随对象实现同样的事情。
我知道可以在 Scala 中使用伴随对象为 Class 声明静态变量和函数,但是有没有办法在 Trait 中声明静态 variables/funcions?
您可以为 trait
设置伴生对象,就像为 class
设置伴生对象一样。
所以你不能在 trait
中声明 static
值,因为 Scala 不那样工作,但你可以使用伴随对象实现同样的事情。