You are probably trying to cast across class loaders. You can't do this--each class loader maintains its own hierarchy (for those classes not passed off to a common parent loader). Try calling
getClassLoader on both your returned map and on a freshly-created one.
Map$Map2 is just an implementation detail--a subclass of
Map for dealing with two-element maps. It casts just fine normally:
scala> val m = Map(1->"one", 2 -> "two"): Object m: Object = Map(1 -> one, 2 -> two) scala> m.getClass res0: Class[_ <: Object] = class scala.collection.immutable.Map$Map2 scala> m.asInstanceOf[scala.collection.immutable.Map[Int,String]] res1: scala.collection.immutable.Map[Int,String] = Map(1 -> one, 2 -> two)
- Convert Java Object (that is really a Scala Map) to Scala Map
- Convert Java Map to Scala Map
- How can I convert Scala Map to Java Map with scala.Float to java.Float k/v conversion
- Convert Scala Any to Java Object
- How to convert java Map to scala Map of type LinkedHashMap[String,ArrayList[String]]?
- How to convert a java Map to immutable Scala map via java code?
- How to convert nested JSON to map object in scala
- How to convert Java Map of Lists to Scala Map of Lists
- Convert Java map into Scala immutable map in Java code with Scala-2.13
- Access from Java a Scala object that inherits from a generic Java base class
- Is there a better way to convert a Scala Map to Java Map?
- Scala object that extends Java class
- Convert Scala map to java Dictionary
- Using Scala in Java - how to convert a Java Object to Option<Object>
- How to convert a java HashMap to immutable Scala map via java code?
- Convert Scala Wrapper$MapWrapper to a Java Map
- Convert Scala nested Map to Java nested util.Map
- How to call Map functions on object that returns Map with type Any in Scala
- How to convert Java Map containing List to Scala map
- Scala: Convert a java list of maps to scala map
- Scala can't convert Java map keySet to a Sequence type
- Use functions from a Scala object that have implicit parameters in java code
- Error while Convert xml to Object or Map in Scala using xstream
- Convert java hashmap to scala map
- How to convert a nested complex scala Map to Java
- Convert a Map into Scala object
- Scala equivalent of Java java.lang.Class<T> Object
- What are the relationships between Any, AnyVal, AnyRef, Object and how do they map when used in Java code?
- How can I convert a Java Iterable to a Scala Iterable?
- Immutable Scala Map implementation that preserves insertion order
More Query from same tag
- Scala: how to avoid passing the same object instance everywhere in the code
- Akka http losing sender reference
- Why do I need to use andThen in order to pattern match Futures?
- Spark DataFrame Summary
- removing layers from a joined RDD and giving names to the elements
- Implicit conversions for members that are types
- Akka StreamTcp timeout restart
- How to do string concatenation in Scala
- Type mismatch: the type referenced in object not the same as the one defined in a trait that object extends?
- Initialize a type variable with dynamic / concrete type
- How to toggle between project and library dependencies in SBT?
- Why it is possible to pass not higher kinded type?
- Adding new arguments to a partial function
- Intellij SBT project: How to change the content roots?
- Replace multiple words on string using Map of replacements
- Print json string in one line using circe in scala
- [Scala][Spark]: transform a column in dataframe, keeping other columns, using withColumn and map [error: missing parameter type]
- Error while writing spark 3.0 sql dataframe to CSV file using scala without Databricks
- How to check if element exist in three lists using scala?
- Why don't the following two functions produce identical output?
- scala slick does not persist data
- How to get week of year in spark 3.0+?
- Error found when importing spark.implicits
- which database to use in Scala (and examples needed)
- Scala Sorting list of two different objects with same fields in abstract class extensions
- Unable to filter DataFrame using Window function in Spark
- Spark-cassandra-connector: toArray does not work
- How to view images from local directories in play scala project
- Clarifying contravariance nature of the return type of a function as parameter a function of an outer convariant container
- Scala-Akka: Log all messages passing by a router