I'm migrating an app from java to Scala. In java I have somethng like
abstract class CommonObjectInfo{//...}
class ConcreteObject extends CommonObjectInfo{//...}
abstract class AbstractWrapper<E extends CommonObjectInfo>{//...}
class ConcreteWrapper extends CommonObjectInfo<ConcreteObject>{//...}
How can I express formally the "wrappers" objects in Scala? I
abstract class CommonObjectInfo
class ConcreteObject extends CommonObjectInfo
abstract class AbstractWrapper[E <: CommonObjectInfo]
class ConcreteWrapper extends AbstractWrapper[ConcreteObject]
The usual solution is the one from agilesteel, but sometimes it's useful to pull the type information "inside" the class (especially when the type in question is considered to be an implementation detail):
abstract class CommonObjectInfo
class ConcreteObject extends CommonObjectInfo
abstract class AbstractWrapper{
type objectInfo <: CommonObjectInfo
}
class ConcreteWrapper {
type objectInfo = ConcreteObject
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With