IllegalType

Since Checkstyle 3.2

Description

Checks that particular classes or interfaces are never used.

Rationale: Helps reduce coupling on concrete classes.

For additional restriction of type usage see also: IllegalInstantiation, IllegalImport

Notes

It is possible to set illegal class names via short or canonical name. Specifying illegal type invokes analyzing imports and Check puts violations at corresponding declarations (of variables, methods or parameters). This helps to avoid ambiguous cases, e.g.: java.awt.List was set as illegal class name, then, code like:


import java.util.List;
...
List list; //No violation here
        

will be ok.

In most cases it's justified to put following classes to illegalClassNames:

  • GregorianCalendar
  • Hashtable
  • ArrayList
  • LinkedList
  • Vector

as methods that differ from interface methods are rarely used, so in most cases user will benefit from checking for them.

Properties

name description type default value since