ABSTRACT

A class member has the same name as the enclosing class.

EXPLANATION

Java allows class members to share the same name as the enclosing class, but taking advantage of this capability usually results in confusing and buggy code.

Example 1: Consider the following class. Imagine trying to debug a problem with it.


public class Name {

private Name Name;

public Name getName() {
return Name.Name;
}
}


Example 2: The following code excerpt from WebGoat demonstrates a bug that manifests itself as a confusing naming issue [1].


public class CreateDB
{
public void CreateDB() { }
...
}


The author intended to create a constructor for the CreateDB class, but inadvertently wrote in a return type (void) and created a regular method instead.

REFERENCES

[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 398

[2] The WebGoat Project OWASP