https://kotlinlang.org logo
#android
Title
# android
r

rohit1899

12/05/2017, 5:40 AM
I have a java class which reads data from some source and casts that data into given class. I pass the class name in which data has to be caste as SomeUserClass.java. How can i pass this info from Kotlin class to java function. I tried SomeUserClass::class.java but it gives me error. This is the java function signature public T getDataFromCache(Class<T> model) { // some operation } and while calling from java i use getDataFromCache(SomeUserClass.class); how can i call this function from Kotlin class ? Thanks in advance
a

adam-mcneilly

12/05/2017, 5:45 AM
Try simply
SomeUserClass::class
?
e

edwardwongtl

12/05/2017, 5:57 AM
Using
SomeUserClass::class.java
works in my case, can you show the error message?
r

rohit1899

12/05/2017, 6:18 AM
@adam-mcneilly when i do SomeUserClass::class i get type mismatch error. Required Class<SomeGroupClass!>! found KCLass<SomeUserClass>
@edwardwongtl i get type mismatch error. Required Class<SomeGroupClass!>! found KCLass<SomeUserClass>
a

adam-mcneilly

12/05/2017, 6:19 AM
You get the same error with or without
.java
at the end?
r

rohit1899

12/05/2017, 6:21 AM
with
.java
i get Unresolved referance. and without java i get type mismatch
a

adam-mcneilly

12/05/2017, 6:23 AM
I took to Google because I think you're doing it right, and I found some stuff suggesting your configuration might be off. I'd double check some of it - https://stackoverflow.com/questions/34144392/kotlin-fooclass-java-unresolved-reference-java-error
r

rohit1899

12/05/2017, 6:28 AM
@adam-mcneilly hey thanks for the link. I had forgot to configure kotlin in my project. I did that and it is not working with SomeUserClass::class.java. Thanks for the help. Cheers !
a

adam-mcneilly

12/05/2017, 6:31 AM
😄
4 Views