简体   繁体   中英

How to translate a java jna interface to kotlin

I am trying to port to kotlin the openvr binding

I have the following in java:

public class IVRSystem extends Structure {

    /**
     * C type : GetRecommendedRenderTargetSize_callback*
     */
    public IVRSystem.GetRecommendedRenderTargetSize_callback GetRecommendedRenderTargetSize;

    public interface GetRecommendedRenderTargetSize_callback extends Callback {

        void apply(IntBuffer pnWidth, IntBuffer pnHeight);
    };
}

Intellij translates it automatically to

var GetRecommendedRenderTargetSize: IVRSystem.GetRecommendedRenderTargetSize_callback? = null

interface GetRecommendedRenderTargetSize_callback : Callback {

    fun apply(pnWidth: IntBuffer, pnHeight: IntBuffer)
}

I changed it then to:

fun getRecommendedRenderTargetSize(pnWidth: IntBuffer, pnHeight: IntBuffer) = GetRecommendedRenderTargetSize_callback.apply(pnWidth, pnHeight)

interface GetRecommendedRenderTargetSize_callback : Callback {

    fun apply(pnWidth: IntBuffer, pnHeight: IntBuffer)
}

but it complains

unresolved reference: apply

Why? How can I fix that?

For reference, C++ code

class IVRSystem
{
    public:
         virtual void GetRecommendedRenderTargetSize( uint32_t *pnWidth, uint32_t *pnHeight ) = 0;
}

GetRecommendedRenderTargetSize_callback is an interface.

The interface itself does not have an apply(IntBuffer, IntBuffer) function but defines such a function for implementing instances of the interface.

You'll need an instance of an object which implements your interface in order to be able to call its "apply" function but such would not be a "port" of the Java code you provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM