object vs val for singletons?
问题描述:
以下哪种方法更好/首选?他们有什么不同?object vs val for singletons?
trait MyService {
def foo: String
}
class MyTest {
// variant 1
object fooService1 extends MyService {
val foo = "foo1"
}
// variant 2
val fooService2 = new MyService {
val foo = "foo2"
}
// (...)
}