简体   繁体   English

我可以在 java 中使用什么来代替 Kotlin 中的 run 函数?

[英]What can I use in java instead of run function in Kotlin?

I try to convert code Kotlin to java and I could not find run function in java.我尝试将代码 Kotlin 转换为 java,但在 java 中找不到运行函数。 This is Kotlin code :这是 Kotlin 代码:

private val resumeArElementsTask = Runnable {
    locationScene?.resume()
    arSceneView!!.resume()
}

And I use resumeArElementsTask like我使用 resumeArElementsTask 之类的

resumeArElementsTask.run {
            computeNewScaleModifierBasedOnDistance(locationMarker, locationNode.distance)
        }

When I convert to java当我转换为 java

private final Runnable resumeArElementsTask = new Runnable() {

    @Override
    public void run() {
        locationScene.resume();
        try {
            arSceneView.resume();
        } catch (CameraNotAvailableException e) {
            e.printStackTrace();
        }

    }
};

How can I use run function in java and convert this code to java如何在 java 中使用 run 函数并将此代码转换为 java

 resumeArElementsTask.run {
            computeNewScaleModifierBasedOnDistance(locationMarker, locationNode.distance)
        }

Thanks谢谢

The following Java code is exactly equivalent to what your Kotlin code actually does:以下 Java 代码与您的 Kotlin 代码实际执行的代码完全相同:

computeNewScaleModifierBasedOnDistance(locationMarker, locationNode.getDistance());

Note that it doesn't resume anything.请注意,它不会恢复任何内容。 Your Kotlin code doesn't, either.您的 Kotlin 代码也没有。 It looks like it does, but it doesn't.看起来确实如此,但事实并非如此。

It sounds like you just want to write听起来你只是想写

runnable.run();
computeNewScaleModifierBasedOnDistance(locationMarker, locationNode.getDistance());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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