Jtest logo




Contents  Previous  Next  Index

CODSTA.DCTOR


Define a default constructor whenever possible

Description

This rule flags code that define a default constructor, but does not.

Default constructors allow classes of unknown types to be dynamically loaded and instantiated at compile time (as is done when loading unknown Applets from html pages). In Java 1.1 and higher, reflection somewhat alleviates the need for no-argument constructors, but many classes that dynamically instantiate other classes at runtime still depend on their presence.

Example

 package CODSTA;
 
 public class DCTOR {  // missing a default constructor.
     public DCTOR(int size) { _size = size; }
     private int _size;
 }

Repair

Define default constructor (no argument).

Reference

http://www.infospheres.caltech.edu/resources/code_standards/recommendations.html


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft