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
}
精彩评论