@native 멤버는 구현을 가질 수 없음
@native 멤버는 구현을 가질 수 없음 (Native Members May Not Have Implementation)
@native 어노테이션이 붙은 메서드에 구현 본문이 있을 때 나오는 에러예요.
본문
@native 어노테이션이 붙은 메서드에 구현 본문이 있으면 이 에러가 발생해요.
@native 어노테이션은 이 메서드의 구현이 런타임이나 네이티브 라이브러리(JNI 같은)에 의해 제공된다는 뜻이에요. 네이티브 메서드는 구현이 Scala 코드 바깥에 존재하므로 본문 없이 선언해야 해요.
예시
class Example:
@native def nativeMethod(): Int = 42
에러 메시지
-- [E066] Syntax Error: example.scala:2:14 -------------------------------------
2 | @native def nativeMethod(): Int = 42
| ^
| @native members may not have an implementation
해결 방법
// Remove the implementation from native methods
class Example:
@native def nativeMethod(): Int
// Or remove @native if you want to provide an implementation
class Example:
def normalMethod(): Int = 42
더 알아보기
- 네이티브 메서드에서는 본문을 빼고, Scala에서 구현을 직접 쓸 거라면
@native를 빼면 돼요.