Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javaBeans without default constructor  RSS feed

 
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... ;-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!