Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala type alias with type parameters

Let the following type alias

class Container[T]
type MyInt = Container[Int]

Is it possible and how to declare a type parameter in a type alias, having tried

type MyInt2 = Container[T <: Int]    // error: ']' expected but '<:' found.
like image 685
elm Avatar asked Aug 13 '14 08:08

elm


1 Answers

You can do:

type MyInt2[T <: Int] = Container[T]

As for other members (e.g. def), type member must declare type parameter in its declaration/signature (left), not in the body (right).

like image 116
cchantep Avatar answered Oct 05 '22 23:10

cchantep