在java代码中使用kotlin库 [英] Using a kotlin library in java code

查看:197
本文介绍了在java代码中使用kotlin库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个kotlin库 FlowLayout lib as aar

I have a kotlin library FlowLayout lib as aar,

并希望在我的java代码(android)中使用它,但无法解析 kotlin.Pair

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 lib及其对象依赖?

I have tried android.support.v4.util.Pair but is not compatible. How can I use a kotlin lib in java code with their object dependencies?

推荐答案

Class kotlin.Pair 属于标准库 org.jetbrains.kotlin:kotlin-stdlib:1.0.0 ,因此您必须将此库作为依赖项。

Class kotlin.Pair belongs to the standard library org.jetbrains.kotlin:kotlin-stdlib:1.0.0, so you must have this library as a dependancy.

不建议在公共API中使用 Pair 。而不是那样,用2个属性创建你自己的数据类并给它们一个比第一个和<$ c更清晰的命名$ c> second 。

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中使用它,则会失去清晰度。

The purpose of Pair is to server as a temporary data carrier in any intermediate operation. If you use it in your API, you lose in clarity.

这篇关于在java代码中使用kotlin库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆