A class member has the same name as the enclosing class.
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;
}
}
public class CreateDB
{
public void CreateDB() { }
...
}
CreateDB
class, but inadvertently wrote in a return type (void
) and created a regular method instead.
[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 398
[2] The WebGoat Project OWASP