• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor Signature for class that extends HttpServletRequestWrapper?

 
Nathan Brennan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and apologies for this noob question!
I'm going through Charles Lyons OCEJWCD Study Companion...
I've just finished Chapter 6 Revision Questions and 2 questions I don't seem to understand. Q17 & Q18 (p153).
I understand why and the use of Wrappers, just not the syntax of the constructor he calls in the above questions.

In the book for Q17 & Q18 (p153) it has :

I thought the constructor would be :
i.e passing the interface type HttpServletRequest so it can get stored on the ServletRequestWrapper instance variable.
Or is his code correct due to HttpServletRequestWrapper passes the IS-A test and is a HttpServletRequest by virtue of HttpServletRequestWrapper implementing HttpServletRequest which extends ServletRequest.??

Sorry . . . confused.com, or I'm just too fried! :-)

Thank you. :-)

 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the book so I can only react on your comments here.

I thought the constructor would be :
public class MyRequestWrapper extends HttpServletRequestWrapper {
public MyRequesterWrapper(HttpServletRequest wrap){
super(wrap);
}
//other code here
}


That is what you normally would do with the wrapper class. It could be a mistake in the book....

Or is his code correct due to HttpServletRequestWrapper passes the IS-A test and is a HttpServletRequest by virtue of HttpServletRequestWrapper implementing HttpServletRequest which extends ServletRequest.??

The code is correct (it compiles and probably runs) and you are correct about the reason, however, I am not sure what the author wants to do with wrapping the wrapper. Is he wrapping somebody else's wrapper class in the question setup?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic