invalid_deprecated_subclass_annotation 진단: 서브클래스 가능 대상에만 쓸 수 있는 애너테이션

invalid_deprecated_subclass_annotation 진단: 서브클래스 가능 대상에만 쓸 수 있는 애너테이션

Dart 분석기가 내보내는 진단에는 이름이 있어요. invalid_deprecated_subclass_annotation@Deprecated.subclass 애너테이션을 서브클래싱(subclassing)할 수 없는 클래스나 mixin에 붙였을 때 분석기가 알려주는 컴파일 타임 진단이에요. 이 애너테이션은 서브클래스할 수 있는 클래스와 mixin에만 붙일 수 있어요.

출처: invalid_deprecated_subclass_annotation

본문

설명

분석기는 서브클래스할 수 있는 클래스나 mixin이 아닌 대상에 @Deprecated.subclass 애너테이션이 적용됐을 때 이 진단을 만들어요. 여기서 서브클래스 가능한 클래스란 final이나 sealed 키워드로 선언되지 않은 클래스를 말하고, 서브클래스 가능한 mixin이란 base 키워드로 선언되지 않은 mixin을 말해요.

예시

아래 코드는 애너테이션을 sealed 클래스에 붙였기 때문에 이 진단이 나와요. sealed 클래스는 더 이상 서브클래스할 수 없으니까요.

@Deprecated.subclass()
sealed class C {}

흔한 해결 방법

애너테이션을 제거하면 돼요.

sealed class C {}

더 알아보기