2
Kotlin은 Java와 동일한 기본 인터페이스 구현을 사용합니까? Java (객체 전송, 바이트 스트림 등)와 마찬가지로 효율적입니까 (또는 비효율적입니까)?Kotlin 기본 인터페이스
Kotlin은 Java와 동일한 기본 인터페이스 구현을 사용합니까? Java (객체 전송, 바이트 스트림 등)와 마찬가지로 효율적입니까 (또는 비효율적입니까)?Kotlin 기본 인터페이스
동일한 Java 코드로 변환되므로 구현이 동일합니다. 이는 Java 코드로서 효율적이라는 것을 의미합니다.
네이티브 메소드 nativeMethod()
와이 코 틀린 클래스를 감안할 때 :
class ExampleJni {
companion object {
init {
System.loadLibrary("example-jni")
}
}
external fun nativeMethod(): String
}
그것은 (변환이 정확히 동일하지 않습니다, 그러나이 영향을주지 않습니다이 자바 클래스의 "동일한"구현을 사용합니다 기본 구현) :
public class ExampleJni {
static {
System.loadLibrary("hello-jni");
}
public final native String nativeMethod();
}
편집
은 변환에 대한 자세한 명확합니다. Kotlin 코드를 디 컴파일하면 두 클래스로 변환됩니다. 첫 번째 기본 방법을 포함한다 :
@dalvik.annotation.MemberClasses
@kotlin.Metadata
public final class ExampleJni {
public static final ExampleJni$Companion Companion;
public ExampleJni() { ... }
static void <clinit>() { ... }
@org.jetbrains.annotations.NotNull
// Here you can see that the implementation is the same.
public final native String nativeMethod() { ... }
}
다른 하나는 companion object
관련된 내부 클래스이다.
@dalvik.annotation.EnclosingClass
@dalvik.annotation.InnerClass
@kotlin.Metadata
public final class ExampleJni$Companion {
private ExampleJni$Companion() { ... }
public ExampleJni$Companion(DefaultConstructorMarker) { ... }
}