Scala mutable collections and "Reference must be prefixed warnings"

pattern-matching, scala, scala-collections

Solution

Just import `mutable` package:

import collection.mutable

and use it with any mutable collection:

mutable.LinkedList(1, 2, 3)

or if you prefer more concise variant:

import collection.{mutable => m}
m.LinkedList(1, 2, 3)

It will work with pattern matching also.

Problem

I have to use a mutable linked list for a specific use case. However I'd like to avoid "Reference must be prefixed" warnings. Aliasing the import seems to be a solution: ``` import scala.collection.mutable.{LinkedList => MutableLinkedList} ``` it works on most cases except in pattern matching an empty LinkedList, this still produces the warning: ``` case MutableLinkedList() => // do Something ``` the only way I can remove this warning seems to be to do a fully qualified case check on an empty list: ``` case scala.collection.mutable.LinkedList() => // do Something ``` Why does the first case not get rid of the warning?

Original source