Is that possible to create a type class based on type parameter by inheriting type parameter like in the code below?
I do suspect that this is fundamentally not possible as this is a scala limitation as functional language...
But if possible what I have to change in the code below??
class MyInt[T : Numeric] extends T {
}
It's not possible. You can extend a class (traits included), but you cannot extend a type , and T
is a type .
Even if it were possible, what would it then mean to have MyInt[Int]
(which is final), or MyInt[List[String]]
(which is not a class) ? It would get quite complicated for the compiler very quickly.
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.