First of all, I know that manifests are deprecated and it is better to use TypeTag, but for now, it is not an option for me, so please consider my problem:
How to check whether type represented by a manifest is a subtype of the type represented by manifest[Numberic[_]]?
Actually, I have a function that receives a manifest and I want to check whether it is numeric or not.
def isNumeric(m: Manifest[T]) : Boolean = m <:< manifest[Numeric[_]]
But, it does not work, eg for an input of manifest[Double].
Any idea, how to make it work?
Numeric
is a type class and it has nothing with subtyping and Manifest
(or TypeTag
).
Double
is not a Numeric
. T : Numeric
in type parameter means there is implicit value of type Numeric[T]
in scope. You can't check it via reflection.
Maybe you could search for implicit in macros
, but I'm not sure and I don't think it's what you are looking for.
So the answer is: You just can't.
It isn't possible even in theory: there is no information about implicit values in runtime and there is no instance of Manifest[T]
in compile time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.