<qhelp>

<overview>

A method that has the same name as its declaring type may be intended to be a constructor, not a method.

</overview> <example>

The following example shows how the singleton design pattern is often misimplemented. The programmer intends the constructor of `MasterSingleton` to be protected so that it cannot be instantiated (because the singleton instance should be retrieved using `getInstance`). However, the programmer accidentally wrote `void` in front of the constructor name, which makes it a method rather than a constructor.

</example> <recommendation>

Ensure that methods that have the same name as their declaring type are intended to be methods. Even if they are intended to be methods, it may be better to rename them to avoid confusion.

</recommendation> <references>

- J. Bloch and N. Gafter, Java Puzzlers: Traps, Pitfalls, and Corner Cases, Puzzle 63. Addison-Wesley, 2005.
- E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of Reusable Objection-Oriented Software, §3. Addison-Wesley Longman Publishing Co. Inc., 1995.
- Help - Eclipse Platform: Java Compiler Errors/Warnings Preferences.
- Java Language Specification: 8.4 Method Declarations, 8.8 Constructor Declarations.
</references> </qhelp>