Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javaBeans without default constructor

 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to everybody,

I have a little tricky question: what happens if:
1. declare a bean without a default constructor with the "class" attribute?
2. declare a bean without a default constractor with the "beanName" attribute?

I supposed that, in the first case, I got 'ClassCastException', but, watching inside the java class create by the application server, it uses reflection to create a new instance.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mirko, accordingly to section JSP.5.1 of the spec:


If the object is not found, and the class is either abstract, an interface, or no public no-args constructor is defined therein, then a java.lang.InstantiationException shall occur. This completes the processing of this jsp:useBean action.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer!

Saying the truth, the doubt was born from a question I found into a mock exam: according to it the page should not get compiled in case of "class" attribute use.

I'll have to pay more attention on the mock exams I find around the web... ;-)
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!