Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why must the init() method call super.init(config)?

 
anirudh bandi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why must the init() method call super.init(config)?
i read on the internet that calling super.init(config) invokes the init() method of GenericServlet , which saves a reference to the config object for future use.
how does it save the reference and why do we need to do this? . can i get a detailed explanation? if possible with an example
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you don't need to do that. You only need to do that if you override the servlet's init(servletConfig) method, which you should not do.
 
anirudh bandi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't understand what you mean can you please elaborate.....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple: You don't need to call the superclass member if you implement the init() method with no parameters. Period.
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anirudh.

Your question seems a little confused. Can you please provide a link to your source?
Having the no-arg init call the super.init(config) makes absolutely no sense to me. Where do you get the config from?

If you override init(config) THEN you should make sure you call its superclass version explicitly super.init(config)
A quick google brings up some relevant articles which can probably explain the issue better: http://javahowto.blogspot.co.nz/2006/06/common-mistake-in-servlet-init-methods.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic