13

I have a kotlin library 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;
     }
});

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?

1
  • Do you have a dependency on the Kotlin library in your Java project (don't remember the artifact name, since they keep changing it, but maybe core)? Commented Jan 2, 2017 at 21:42

1 Answer 1

19

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.

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.

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.