[英]Method parameter must be obj of certain class that implements certain interface
[英]Why is ServletConfig obj passed to init() of GenericServlet when the class implements the interface?
GenericServlet
实现了ServletConfig
接口,这意味着可以从GenericServlet
init()
函数调用所有接口函数。 鉴于此上下文,为什么Servlet容器将ServletConfig
对象发送到init()
方法? 我还想知道传递给GenericServlet.init(ServletConfig)
的ServletConfig
对象是否与GenericServlet对象不同。
此致,拉维
GenericServlet
通过简单地委托传递给init方法的配置对象来实现ServletConfig
方法。 所以它为了方便起见实现了ServletConfig
- 然后简单地委托。 因此,您可以调用getInitParameter()
而不是调用getServletConfig().getInitParameter()
getInitParameter()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.