Is it possible in Scala to define MyAlias[A] as an alias for MyClass[String, A]. For example, MyAlias[Int] would refer to Map[String, Int].
Is it possible in Scala to define MyAlias[A] as an alias for MyClass[String, A]
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note that
Mapis atrait, not aclass.You can still alias it using the
typekeyword:This can be done within the scope of a
class,objectortraitdefinition (and in the scope of any method or expression).Sometimes you’ll want the alias to be private to its declaring scope, purely as a convenience for your implementation code. If you want the type to be usable generally, Package Objects come in useful:
Because
Mapis a trait (and associated companion object) and not a class, you won’t be able to use it directly to create instances:If you alias a class, though, you can still use the
newkeyword: