추상 멤버는 수식어를 가질 수 없음
추상 멤버는 수식어를 가질 수 없음 (Abstract Member May Not Have Modifier)
추상 멤버를 final이나 private처럼 추상과 어울리지 않는 수식어와 함께 선언했을 때 나오는 에러예요.
본문
추상 멤버를 추상과 호환되지 않는 수식어(예: final, private)와 함께 선언하면 이 에러가 발생해요.
추상 멤버는 서브클래스가 구현하도록 만들어진 것이므로, final(오버라이드를 막음)이나 private(서브클래스의 접근을 막음)과는 함께 쓸 수 없어요.
예시
trait Example:
final def abstractMethod: Int
에러 메시지
-- [E060] Syntax Error: example.scala:2:12 -------------------------------------
2 | final def abstractMethod: Int
| ^
| abstract method abstractMethod may not have `final` modifier
해결 방법
// Remove the incompatible modifier
trait Example:
def abstractMethod: Int
// Or provide an implementation if you want final
trait Example:
final def concreteMethod: Int = 42
더 알아보기
- 어울리지 않는 수식어를 빼거나,
final이 꼭 필요하다면 구현을 함께 제공하면 돼요.