Can’t figure out why this does not work:
def f[A: Double](x: A) = x / 4 // error: "Double does not take type parameters"
println(f(87.7))
While this one works:
def f[A <: Double](x: A) = x / 4
println(f(87.7))
The only difference is that in the first case I just specify particular type, and in the second I define type upper bound.
That’s because
[A: Double]is not a correct way to define a type parameter. This form is applicable to define aclass manifestcontext bound (new in Scala 2.8 – thanks @mhs for the link); however, theClassManifest[T]type used to represent context bounds is a parameterized type, soDoubleis not fit as a class manifest.Note though that context bounds and manifests were introduced to solve the problem of generic array creation, so there is no point using one here, as your function – as it is shown above – has nothing to do with arrays.