E116: Missing Companion for Static
E116: Missing Companion for Static (@static를 위한 컴패니언 클래스 없음)
@static 멤버를 가진 object에 컴패니언(companion) 클래스가 없을 때 나오는 에러예요.
본문
@static 멤버를 가진 object는 반드시 컴패니언 클래스가 있어야 해요. static 멤버가 컴패니언 클래스의 바이트코드에 배치되기 때문이에요.
예시
import scala.annotation.static
object Example:
@static val count = 0
에러 메시지
-- [E116] Syntax Error: example.scala:4:14 -------------------------------------
4 | @static val count = 0
| ^^^^^^^^^^^^^^^^^^^^^
| object Example does not have a companion class
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| An object that contains @static members must have a companion class.
-----------------------------------------------------------------------------
해결 방법
컴패니언 클래스를 추가하거나, 정적 동작이 필요 없다면 @static을 제거하면 돼요.
// Add a companion class
import scala.annotation.static
class Example
object Example:
@static val count = 0
// Or remove @static if you don't need static behavior
object Example:
val count = 0