Two classes can have the same simple name if they are in two different packages.
package org.foo.domain; public class User { // .. }
package org.foo.presentation; public class User { // .. }
However, this becomes an issue when a class has the same name as the superclass it extends or the interfaces it implements, also known as class name shadowing. It is problematic because it can be unclear which class is being referred to in the code, leading to ambiguity and potential bugs.
Therefore, it is recommended to use unique and descriptive class names that do not conflict with the names of the superclass or interfaces.
This rule raises an issue when a class name shadows its superclass or interface names.
Rename the class using a more descriptive name.
package org.foo.presentation; public class User implements org.foo.domain.User { // Noncompliant // ... }
package org.foo.presentation; import org.foo.domain.User; public class UserView implements User { // Compliant // ... }