conflicting_constructor_and_static_member 진단: 생성자와 static 멤버의 이름 충돌

conflicting_constructor_and_static_member 진단: 생성자와 static 멤버의 이름 충돌

Dart 분석기가 만들어 내는 conflicting_constructor_and_static_member 진단에 대한 설명이에요.

출처: conflicting_constructor_and_static_member

본문

이름이 있는 생성자(named constructor)와 static 메서드나 static 필드가 같은 이름을 가지면 분석기가 이 진단을 만들어요. 둘 다 클래스 이름으로 접근하기 때문에, 이름이 같으면 참조가 애매해져요.

예시

다음 코드는 static 필드 foo와 이름 있는 생성자 foo가 같은 이름을 가져서 이 진단을 만들어요.

class C {
  C.foo();
  static int foo = 0;
}

다음 코드는 static 메서드 foo와 이름 있는 생성자 foo가 같은 이름을 가져서 이 진단을 만들어요.

class C {
  C.foo();
  static void foo() {}
}

흔한 해결 방법

멤버나 생성자 중 하나의 이름을 바꿔주면 돼요.

더 알아보기