有人可以帮我将这个带有回调的 Kotlin 函数转换为 java 函数吗?

Can someone help me on converting this Kotlin function with callback to a java function?

到目前为止我还没有接触过 kotlin。因此,我发现很难理解这个 'callback' 实际上是如何工作的。因此,我无法弄清楚如何将 kotlin 的 'callback' 特性写入 java。

fun stopStream(callback:(text:String)->Unit) {
        if(bidiStream == null) return

        bidiStream?.closeSend()

        for (response in bidiStream!!) {
            val queryResult = response.queryResult

            Log.d(TAG, "Response Text: '${queryResult.responseText}'")
            callback(queryResult.responseText)
        }

        bidiStream = null
        queryInput = null
    }

你知道很多 IDE 都提供这样的转换吗?

(text:String)->Unit 接受一个 String 并且不产生任何东西,所以它是一个 Consumer<String>。除此之外变化不大

void stopStream(Consumer<String> callback) {
    if(bidiStream == null) return;

    bidiStream.closeSend();

    for (Response response: bidiStream) {
        var queryResult = response.getQueryResult();

        Log.d(TAG, String.format("Response Text: %s"), queryResult.getResponseText());
        callback(queryResult.getResponseText());
    }

    bidiStream = null;
    queryInput = null;
}