This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I read 2 conflicting things in 2 different places. One says a constructor needs to run before the init() method can be run, because a constructor creates an object while the init() method gives the object servlet-specific capabilities. The other says that a constructor can replace the init() method, and everything that is done in the init() method can be done in the constructor itself.
I am confused as to which is correct. Can we really combine the constructor and init() method and make it into a constructor? thereby doing away with the init() method?
Souvvik Basu wrote:The other says that a constructor can replace the init() method, and everything that is done in the init() method can be done in the constructor itself.
If you read this at a website, remove its bookmark and be sure to never ever visit it again.
If you read it in a book, burn it, then soak the ashes in hydrochloric acid for 10 hours. Then put the ashes into a rocket and fire it into the sun.
It is false. In fact it so stupidly false as to be terrifying.
You can put code in the constructor, sure. But there really shouldn't be anything worth putting in a constructor. And if you do create a constructor for your servlet, you're just going to confuse the next person who has to maintain it, if (as appears likely) they don't have a good grasp of the basic concepts.