jQuery in Action, 3rd edition
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 REST with Spring (video course) this week in the Spring 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: 5091

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: 20183

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: http://aspose.com/file-tools
subject: Constructor returns an object?
jQuery in Action, 3rd edition