How does method chaining work?

后端 未结 2 1022
别那么骄傲
别那么骄傲 2020-12-12 08:02

How does getRequestDispatcher(\"xxx\") get called from getServletContext() in the example below? How does calling procedures like this work in gene

2条回答
  •  不思量自难忘°
    2020-12-12 08:59

    getServletContext() returns a ServletContext object, which has a method called getRequestDispatcher(). Your line of code is just shorthand for two method calls, and is equivalent to this code:

    ServletContext context = getServletContext();
    RequestDispatcher dispatcher = context.getRequestDispatcher("/index.jsp");
    

提交回复
热议问题