def homepageClass[A <: SomeType]: Class[A]
says "whatever subclass A
of SomeType
you give, I can return a Class[A]
. In particular, it can be called like this:
class SomeThirdType extends SomeType
val x: Class[SomeThirdType] = SomeObject.homepageClass[SomeThirdType]
A more direct equivalent than Daniel gives is an existential type:
trait SomeTrait{
def homepageClass: Class[A forSome {type A <: SomeType}]
}
or
trait SomeTrait{
def homepageClass: Class[_ <: SomeType]
}
UPDATE: Two differences between solutions I can think about:
Existential types produce the same bytecode as Java wildcards (and their major intended use is interoperation with wildcards).
You can write a refinement type for the abstract type member solution:
val x: SomeTrait {type A = SomeOtherType} = SomeObject
I don't think you can for existential types.
Any others?