How it is possible to create object for HttpServletRequest
Interface?
如何为HttpServletRequest接口创建对象?
HttpServletRequest
is an interface, but still servlet container can create object of the same. How? Why?
HttpServletRequest是一个接口,但仍然是servlet容器可以创建相同的对象。怎么样?为什么?
1 个解决方案
#1
5
The servlet container has a class implementing this interface, and instantiates an object of this class. Just like when you do
servlet容器有一个实现此接口的类,并实例化该类的对象。就像你做的那样
List<String> list = new ArrayList<String>();
List
is an interface, and you instantiate ArrayList
, which is a class implementing List
.
List是一个接口,您实例化ArrayList,它是一个实现List的类。
The servlet container does something like the following:
servlet容器执行以下操作:
HttpServletRequest request = new TomcatHttpServletRequestImpl();
This is the basis of OO and polymorphism.
这是OO和多态性的基础。
#1
5
The servlet container has a class implementing this interface, and instantiates an object of this class. Just like when you do
servlet容器有一个实现此接口的类,并实例化该类的对象。就像你做的那样
List<String> list = new ArrayList<String>();
List
is an interface, and you instantiate ArrayList
, which is a class implementing List
.
List是一个接口,您实例化ArrayList,它是一个实现List的类。
The servlet container does something like the following:
servlet容器执行以下操作:
HttpServletRequest request = new TomcatHttpServletRequestImpl();
This is the basis of OO and polymorphism.
这是OO和多态性的基础。