Scala creating an instance of type alias

Viewed 43

I am wondering how to create an instance of type alias. More specifically this:

type Graph = scala.collection.mutable.Map[Statement, Statement]

I tried this but I get a type error saying Map[Statement, Statement] is not equivalent to Graph:

val graph: Graph = Map[Statement, Statement]().asInstanceOf[Graph]

Is this (i.e. creating a type alias) anti-pattern in Scala?

1 Answers

Map[?,?] is always immutable except when an import might shadow it.

This works:

val graph: Graph = collection.mutable.Map[Statement, Statement]()
Related