Home > Net >  What is the name of the Long class in Kotlin JNI?
What is the name of the Long class in Kotlin JNI?

Time:06-29

This Kotlin function

 @JvmStatic external fun registerNativeWindowFromSurface(): Integer;

is found by with return type java/lang/Integer but when I add a Long:

 @JvmStatic external fun registerNativeWindowFromSurface(id: Long): Integer;

I cannot find it with java/lang/Long in the argument.

Is Kotlin's Long a java long or a java/lang/Long? How can I get a Long class?

CodePudding user response:

Integer is not the Kotlin-native integer type. Integer is an alias to java.lang.Integer. Int is the Kotlin integer type.

@JvmStatic external fun registerNativeWindowFromSurface(): Int
@JvmStatic external fun registerNativeWindowFromSurface(id: Long): Int

These will compile to functions with signatures

int registerNativeWindowFromSurface();
int registerNativeWindowFromSurface(long id);

And the class instance for the primitive type int is java.lang.Integer.TYPE. Likewise for long and java.lang.Long.TYPE.

If you actually intend to use Java boxed types, you can reference them with their fully qualified names.

@JvmStatic external fun registerNativeWindowFromSurface(): java.lang.Integer
@JvmStatic external fun registerNativeWindowFromSurface(id: java.lang.Long): java.lang.Integer
  • Related