• Post Reply Bookmark Topic Watch Topic
  • New Topic

no argument constructor in beans  RSS feed

 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why should there be a no argument constructor in beans?
can't there be a any overloaded costructor with no arg ones?
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
default constructor is must. useBean designed like that
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Javabean specification mentioned that bean should have no arg constructor.

Here you get specification
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.

 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aruna sameera wrote:why should there be a no argument constructor in beans?
can't there be a any overloaded costructor with no arg ones?


Yes, you can have as many overloaded constructors as you'd like. But many JavaBeans tools (like the JSP "useBean" tag already mentioned) expect to be able to create a JavaBean using only the name of the class -- i.e., they'll call

Object bean = Class.forName(theClassName).newInstance();

For this to work, there must be a no-argument constructor. If you give your class other constructors, then you can use those constructors explicitly in your code. But tools will always use the no-argument one.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!