Tomcat 7中的Scala - HttpServletRequest.getHeaderNames返回java.util.Collection而不是Enumeration?

时间:2013-02-25 09:11:31

标签: scala tomcat7 scala-collections

将Scala与Tomcat 7一起使用时,HttpServletRequest.getHeaderNames()显然将java.util.Collection而不是java.util.Enumeration作为indicated in docs返回。

这里会发生一些隐式转换吗?

更具体地说,以下servlet:

import java.io._
import javax.servlet._
import javax.servlet.http._

class TomcatScalaExample extends HttpServlet {
    override def doGet (req: HttpServletRequest, res: HttpServletResponse): Unit = {
        val out = res.getWriter()
        out.println(res.getHeaderNames.getClass.getCanonicalName)
        out.close()
    }
}

在浏览器中打印以下内容:

java.util.ArrayList

虽然我期待与java.util.Enumeration相关的东西。

作为参考,这是用-Xprint:typer:

编译的代码
   [scalac] package pl.kamituel.tomcatscalaexample {
   [scalac]   import java.io._;
   [scalac]   import javax.servlet._;
   [scalac]   import javax.servlet.http._;
   [scalac]   class TomcatScalaExample extends javax.servlet.http.HttpServlet {
   [scalac]     def <init>(): pl.kamituel.tomcatscalaexample.TomcatScalaExample = {
   [scalac]       TomcatScalaExample.super.<init>();
   [scalac]       ()
   [scalac]     };
   [scalac]     override def doGet(req: javax.servlet.http.HttpServletRequest, res:     javax.servlet.http.HttpServletResponse): Unit = {
   [scalac]       val out: java.io.PrintWriter = res.getWriter();
   [scalac]       out.println(res.getHeaderNames().getClass().getCanonicalName());
   [scalac]       out.close()
   [scalac]     }
   [scalac]   }
   [scalac] }
   [scalac]

0 个答案:

没有答案