- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Wrapping a Servlet ParameterMap
Sun, 2009-04-12, 01:42
def wrapParameterMap(pMap: java.util.Map[String, Array[String]]):
scala.collection.Map[String, Array[String]] = {
new jcl.MapWrapper[String, Array[String]] {
override def underlying() = parameterMap
}
}
When I pass try to pass an HttpServletRequest#getParameterMap to my function I get this error:
found : java.util.Map[?0,?1] where type ?1, type ?0
required: java.util.Map[String,Array[String]]
I'm always running into these types of errors when trying to get Scala collections to work with collections from various java frameworks. I read the section in "Programming in Scala", but It's still a little over my head.
scala.collection.Map[String, Array[String]] = {
new jcl.MapWrapper[String, Array[String]] {
override def underlying() = parameterMap
}
}
When I pass try to pass an HttpServletRequest#getParameterMap to my function I get this error:
found : java.util.Map[?0,?1] where type ?1, type ?0
required: java.util.Map[String,Array[String]]
I'm always running into these types of errors when trying to get Scala collections to work with collections from various java frameworks. I read the section in "Programming in Scala", but It's still a little over my head.
On Sat, Apr 11, 2009 at 07:42:24PM -0500, Erick Fleming wrote:
> found : java.util.Map[?0,?1] where type ?1, type ?0
> required: java.util.Map[String,Array[String]]
That's because you've been given a Map[_,_] and are trying to pass it
off as a Map[String,Array[String]].
The best thing to do is not deal with methods which want to give you raw
types. If you must, then cast your way out.
// look ma, I know what it is
m.asInstanceOf[java.util.Map[String,Array[String]]
> I'm always running into these types of errors when trying to get Scala
> collections to work with collections from various java frameworks.
Raw types just can't make the leap into scala the way they are without
compromising the type system. Just cast them as soon as you get them --
"problem solved" for generous definitions of solved.