13

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.

1 Answer 1

22

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.