This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Constructor returns an object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructor returns an object?" Watch "Constructor returns an object?" New topic

Constructor returns an object?

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
I have seen this code snippet:

How could this work? As far as I know it's only allowed to call a constructor after the "new" keyword.

We must know, we will know. -- David Hilbert
Darryl Burke

Joined: May 03, 2008
Posts: 5045

I'm not familiar with Spring, but the line of code you posted implies that the class in which it's written has a method BeanWrapperImpl (or has a static import for that static method of another class) which takes can take a Company argument.

Someone please correct me if that's wrong in the Spring context.

luck, db
There are no new questions, but there may be new answers.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20132

Either that or they forgot to add the new keyword.

How To Ask Questions How To Answer Questions
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
It looks like an error. It should be new BeanWrapperImpl(new Company()) as shown here.

The BeanWrapperImpl class has many overloaded constructors.
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Thank you guys.
I agree. Here's the link:
subject: Constructor returns an object?
It's not a secret anymore!