简体   繁体   English

Kotlin 流入 Java

[英]Kotlin Flow in Java

I have been trying to find some good resources that point to Kotlin Flow usage/integration in java applications but I couldn't find any.我一直试图在 java 应用程序中找到一些指向 Kotlin 流使用/集成的好资源,但我找不到任何资源。 Can we use Kotlin Flow (SharedFlow/StateFlow) in Kotlin based applications that might be integrated in other Java based projects.我们能否在基于 Kotlin 的应用程序中使用 Kotlin 流(SharedFlow/StateFlow),这些应用程序可能集成在其他基于 Java 的项目中。

Technically, you can use any Kotlin APIs from Java, including flows and coroutines.从技术上讲,您可以使用 Java 中的任何 Kotlin API,包括流和协程。

In practice , any attempt to use Flows directly from Java is likely to be so difficult to do correctly that you shouldn't bother trying.实践中,任何直接从 Java 使用 Flows 的尝试都可能很难正确执行,因此您不必费心尝试。 So don't.所以不要。 Instead, write Kotlin APIs that expose a non-coroutine API and wrap flows, and then use those from Java if you must.相反,编写 Kotlin API 以公开非协程 API 并包装流,然后如果必须使用 Java 中的 API。

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

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