• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt in filter  RSS feed

 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello joseph here

i know instanceof operator , wheather an object is a subclass of class or it implements any interface .
my question is the followoing code


then how it is being executed within if block
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here using instanceof operator we make sure that only http request object are getting filtered out!

Its a way of safe programing !
 
joseph prabhu
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sagar Rohankar:
here using instanceof operator we make sure that only http request object are getting filtered out!

Its a way of safe programing !


joseph here
that is ok
if(reqeust instanceof HttpServletRequest) gives as if(true)

request is a superclass object it cant be assigned to subclass object

can you explain technically.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by joseph prabhu:


if(reqeust instanceof HttpServletRequest) gives as if(true)

request is a superclass object it cant be assigned to subclass object

can you explain technically.


No , here you have reference of type ServletRequest class , but until run time , you don`t know which object it referring , So at the run time you check for the correct instance of request using instanceof operator in filter code , which is nothing but object of HttpServletRequest..

Hope this clarifies .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!