Scala: Is it possible to restrict a type parameter to non-abstract?
Are there any other restrictions besides view boundaries, upper bounds and lower bounds for type parameters and elements of an abstract type? In C #, for example, with which I am familiar, you have additional common limitations:
where T: Class // Not sure if this is described in Scala from T <: AnyRef
where T: interface
where T: struct
where U: T // restriction of bare type
where T: new () // This ensures that the type parameter is not abstract and allows you to instantiate the type object in the generic class.
The latter is especially important, as it allows you to create your own unknown type, although you can forbid a constructor without parameters with its shame.
Can =: = <: <and <% <only for method parameters?
"T: new()" - .
class ExampleClass[T <: AnyRef] {
val example: T = new T()
}
# #. , , #, , "T: numericType". Scala. Scala, , , , Scala, , Scala.
, , , (Eclipse 2.1.0.M1 Eclipse 3.7.2) . , , . , :
abstract class Descrip [T <: DTypes]()
{
val hexs: MutableList[T#HexT] = new MutableList[T#HexT] //compiles fine
val sides: MutableList[T#SideT] = new MutableList[T#SideT] //compiles fine
}