我有一个kotlin图书馆FlowLayout lib as aar

and want to use it in my java code (android) but can not to resolve kotlin.Pair.

FlowLayoutManager layoutManager=new FlowLayoutManager(3, RecyclerView.HORIZONTAL, new FlowLayoutManager.Interface() {
    @Override
     public kotlin.Pair<Integer, Integer> getProportionalSizeForChild(int i) {
         return null;
     }
});

我试了android.support.v4.util.Pair次,但不兼容.如何在java代码中使用kotlin库及其对象依赖关系?

推荐答案

kotlin.Pair属于标准库org.jetbrains.kotlin:kotlin-stdlib:1.0.0,因此必须将此库作为从属库.

It is NOT recommended to use Pair in public APIs. Rather than that, create your own data class with 2 properties and give them a clearer naming than first and second.

Pair的目的是在任何中间操作中将服务器作为临时数据载体.如果在API中使用它,就会失go 清晰度.

Kotlin相关问答推荐

如果一项工作失败,请继续在Kotlin 等待其他工作/子元素完成

Kotlin和JavaFX:绑定行为奇怪

使用另一个对象的列表创建对象

Kotlin编译器如何决定是否可以在任何给定点调用Suspend方法?

通过快捷键手动砍掉功能参数等

在 kotlin 中使具体化字段可选

如何在 kotlin 中使用带有泛型的密封类

使用 LazyListScope 嵌套可组合项

如何为 material.Slider 视图创建绑定适配器?

为什么 android studio 不为所有安全参数生成代码?

为什么我在使用 Jetpack Compose clickable-Modifier 时收到后端内部错误:Exception during IR lowering error?

如何从 Firestore 查询中排除元素?

Kotlin 单元测试 - 如何模拟 Companion 对象的组件?

作为 Kotlin 中的函数的结果,如何从 Firestore 数据库返回列表?

如何在使用 Gradle 的 AppEngine 项目中使用 Kotlin

Kotlin协程处理错误和实现

用mockk验证属性设置程序吗?

Kotlin Flow 收集后无法执行代码

我应该在哪里调用 MobileAds.initialize()?

带有注释为@RegisterExtension的字段的 JUnit 5 测试在 Kotlin 中不起作用