0
以下哪種方法更好/首選?他們有什麼不同?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"
}
// (...)
}