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

HF-EJB: Uncaught Error?  RSS feed

 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's with the newInstance() on pages 463, question 3 and its corresponding answer on page 466? Do they mean a call to a constructor? It is not in the errata so maybe I misunderstood something?

Anybody has the answer?

Thanks!
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Alicea:
What's with the newInstance() on pages 463, question 3 and its corresponding answer on page 466? Do they mean a call to a constructor? It is not in the errata so maybe I misunderstood something?

Anybody has the answer?

Thanks!


Yes, they do. Because classes are created using DD info, each class object has got a newInstance() method which invokes the default, no-arg constructor.

Here follows the signature (from J2SE API):

 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, Marco.

Researching your answer, I see that the process to invoke the default constructor would be (?)

MyBeanClass.getClass().newInstance()

which is different from

MyBeanClass.newInstance() which is what the example in the book suggests.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!