Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface problem.

 
CoffeeFan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Since methods can not be defined but be declared in an interface. Am I right? Why can we invoke the method of interface HttpServletRequest directly without causing any error(like what is usually done in doPost() function)? Where are the implementation of those methods?
Many thanks.
 
Paul McKenna
Ugly Redneck
Ranch Hand
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The signature of the method is

But what is actually passed into the method are objects that implements the respective interfaces. Each server may implement the two objects in different ways, but for a developer to understand all you need is a reference to the top level interface.
SR
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by CoffeeFan:
Hi,
Since methods can not be defined but be declared in an interface. Am I right? Why can we invoke the method of interface HttpServletRequest directly without causing any error(like what is usually done in doPost() function)? Where are the implementation of those methods?
Many thanks.

Hey there.
The reason that this works is that the object passed to doPost etc is a concreate implementation fo the interface provided by the vendor of your webcontainer.
So when you call a method on the HttpServletRequest interface, you are really callign a methhod on the underlying concrete implementation.
Hope this clears things up for you.
Cheers
Sam
 
Bill Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One point I want to add is that the concrete implementation class for HttpServletRequest is provided by the servlet engine automatically and transparent to the developer.
 
CoffeeFan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.
Thank you very much for your explanations. I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic