【问题标题】:How to translate a java jna interface to kotlin如何将 java jna 接口转换为 kotlin
【发布时间】:2017-03-02 04:58:13
【问题描述】:

我正在尝试将openvr binding 移植到 kotlin

我在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 会自动将其翻译成

var GetRecommendedRenderTargetSize: IVRSystem.GetRecommendedRenderTargetSize_callback? = null

interface GetRecommendedRenderTargetSize_callback : Callback {

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

我后来改成了:

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

interface GetRecommendedRenderTargetSize_callback : Callback {

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

但它抱怨

未解决的参考:应用

为什么?我该如何解决?

C++ 代码供参考

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

【问题讨论】:

    标签: java intellij-idea interface kotlin jna


    【解决方案1】:

    GetRecommendedRenderTargetSize_callback 是一个接口。

    接口本身没有apply(IntBuffer, IntBuffer)函数,但定义了这样一个函数来实现接口的实例。

    您需要一个对象的实例来实现您的接口,以便能够调用其“应用”函数,但这不是您提供的 Java 代码的“端口”。

    【讨论】:

    • 你的意思是ivrSystem.GetRecommendedRenderTargetSize.apply(...)?因为它应该是这样的
    猜你喜欢
    • 2019-03-12
    • 2019-01-29
    • 2018-11-26
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多