Skip to content

Files

Latest commit

 

History

History
39 lines (26 loc) · 898 Bytes

MemberNameEqualsClassName.md

File metadata and controls

39 lines (26 loc) · 898 Bytes

Pattern: Member name equals class name

Issue: -

Description

Reports a member that has the same name as the containing class or object. This might result in confusion. The member should either be renamed or changed to a constructor. Factory functions that create an instance of the class are exempt from this rule.

Example of incorrect code:

class MethodNameEqualsClassName {

    fun methodNameEqualsClassName() { }
}

class PropertyNameEqualsClassName {

    val propertyEqualsClassName = 0
}

Example of correct code:

class Manager {

    companion object {
        // factory functions can have the same name as the class
        fun manager(): Manager {
            return Manager()
        }
    }
}

Further Reading