Upper bounds in Scala

Viewed 564

I am trying to set Upper Bounds for a variable.

trait Container {
type A <: Number
def value: A
}

Then when I try to get a value for my

object AnyNumber extends Container {
def value = 2
}

I get this error

<console>:25: error: overriding type A in trait Container with bounds <: Number;
 type A has incompatible type
   type A = Int
        ^
3 Answers
Related