2

I have a class one in java which implements AsyncTask and other is kotlin MainActivity.

Now I have a kotlin function with kotlin int as parameter in MainActivity. I have managed to call kotlin function in java class but unable to pass Java Integer,it shows compile time error. Is there any way to pass integer value?

2
  • 1
    What is the compile error and crash log? Commented Jul 24, 2019 at 4:35
  • I don't think using String is correct. Int should be able to be passed via an Integer object Commented Jul 24, 2019 at 4:38

3 Answers 3

2

Java using int instead Integer,
and in java to parse integer to string using Integer.toString(k)

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

Comments

1

From your post, I guess that the compile error occurred due to using int instead of Int in Kotlin. Change your kotlin function to this

fun kotlinfun(i: Int){
    ...
}

and call normally in java class

int k=0;
obj.kotlinfun(k);

Comments

0

Try it:

int k=0;
obj.kotlinfun(String.valueOf(k));
  • Convert using Integer.toString(int)
  • Convert using String.valueOf(int)
  • Convert using new Integer(int).toString()
  • Convert using String.format()
  • Convert using StringBuffer or StringBuilder.

Comments

Your Answer

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