You can return simply collection.Map
, which is a common supertype of collection.mutable.Map
and collection.immutable.Map
:
def func(): collection.Map[Int, Int] = {
val map = mutable.HashMap[String, Int]
// here goes operations for the map
return map
}
The users could cast it to mutable.Map
, but they could also get the mutable map by reflection in any solution which avoids copying, or mutate the immutable map even when you do copy.