aspose file tools*
The moose likes Java in General and the fly likes Is explicit no-argument constructor a must? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is explicit no-argument constructor a must?" Watch "Is explicit no-argument constructor a must?" New topic
Author

Is explicit no-argument constructor a must?

M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
My class (BonusDetailAction extends org.apache.struts.action.Action) doesn't have any constructors. But, according to JTest report:
Is no argument constructor is a must in the class?
I googled for the same, but I got both the answers YES and NO.

I require my dear ranchers opinion, please help.


R6i
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Rayapudi,

in my opinion nothing is a must or should be a must. If it makes sense to have a no-arg constructor you should have one. If you don't really need it, why should you have one? Of course some frameworks etc. force you to have no-arg constructors in practice but that's another story. If you rely on such a framework you will hardly get around such technical limitations, even if you actual business logic doesn't require a no-arg constructor. Often it is even helpful for a good application design to "document" explicit dependencies as arguments in constructors. This helps to show the dependencies and reminds you if you have too much of them

That said, I'm just not sure how this relates to testing? What does your test look like? Which version of JUnit are you using?

Marco

M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
thank you Marco,
I'm just not sure how this relates to testing?
Jtest reported this kind of suggestion, so that, I thought it is better to post in Testing. I am requesting moderators to move this thread to Java Programming (or more appropriate one).
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Moved as requested.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Aah, now I see

Sorry, I just read JTest and thought of JUnit tests Now it's clearer and I think it's not wrong in this forum.

The answer to you question still stays the same: It depends No matter if you're using JTest, FindBugs, PMD, Checkstyle or anything similar you will always get hints and advices that shouldn't be used as strict rules. Unfortunately I don't know JTest so I can't tell you more about it why it would like to see a no-arg constructor for your class. Possibly there's any documentation what triggers this message?!?

Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is explicit no-argument constructor a must?