I'm looking at scala types of types self types annotation
it says that new Service
cannot be instantiated because of the usage of self type
in favor of extends
. But I tried the example also with extends
and it still does not compile.
class TryMe {
class ServiceInModule {
def doTheThings() = "dfdf"
}
trait Module {
lazy val serviceInModule = new ServiceInModule
}
trait Service extends Module {
def doTheThings() = serviceInModule.doTheThings()
}
trait TestingModule extends Module {
}
new Service
}
Error:(22, 3) trait Service is abstract; cannot be instantiated new Service ^
Am I missing something? why does it claim that with extends it should compile? it does not compile...