Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Aysel Kaya   on Jun 27 In Java Category.

  
Question Answered By: Abana Cohen   on Jun 27

The long line of code:
String
myFile=getServletConfig().getServletContext().getRealPath(myRequestFile);

is the same as:

ServletConfig servletConfig = getServletConfig();
ServletContext servletContext = servletConfig.getServletContext();
String myFile = servletContext .getRealPath(myRequestFile);

Its just all chained together.

The object first in the chain, pulls on the next in line which pulls the
next in line without having to explicitly giving a name for each step of
the way.

You can chain the methods and shorten your code.

After a point its gets less readable, from the programmer's point of view.

It all could also be shortened to:

String
pathToMyFile=getServletConfig().getServletContext().getRealPath(request.getServl\
etPath());

I was looking at the documentation and it appeared that
getServletConfig().getServletContext().
was redundant.

Share: 

 
 
Didn't find what you were looking for? Find more on Multiple Method Calls Or get search suggestion and latest updates.


Tagged: