Modifier Checks

Modifier Order

Checkstyle checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is:

  1. public
  2. protected
  3. private
  4. abstract
  5. static
  6. final
  7. transient
  8. volatile
  9. synchronized
  10. native
  11. strictfp

Redundant Modifiers

Checkstyle checks that method declarations in interfaces do not include the abstract modifier (see the Java Language specification, section 9.4).

The property checkstyle.ignore.public.in.interface defines whether to ignore the public modifier in interface definitions (see the Java Language specification, section 9.4)). The property type is boolean and defaults to false.

Visibility Modifiers

Checkstyle checks for class data members that are not declared private. It also checks for static non-final data members that are not declared as private.

The property checkstyle.allow.protected defines whether to allow protected class data members. The property type is boolean and defaults to false.

The property checkstyle.allow.package defines whether to allow package protected class data members. The property type is boolean and defaults to false.

The property checkstyle.pattern.publicmember defines the format for public class data members that are allowed to be public. The property type is regular expression and defaults to ^f[A-Z][a-zA-Z0-9]*$.

Tip

Container Managed Persistence EJBs require (in the EJB 1.1 specification) that managed fields are declared public. This will cause Checkstyle to complain that the fields should be declared private. The property checkstyle.pattern.publicmember is ideal for this situation.


Copyright © 2002 Oliver Burn. All rights Reserved.