Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Interface problem.

 
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.
 
Ugly Redneck
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
 
Author
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
 
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.
 
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic