简体   繁体   中英

Generic class input param type miss match

Always get an Error type mismatch, when input param for getObjectSingle . how do I fix with my generic wrapper class?

在此处输入图片说明

在此处输入图片说明

You need the class not the instance, but you must create an instance of the class to get class itself, try this:

val wrapper = Wrapper<String>()

Rx2AndroidNetworking.post(someUrl)
        .build()
        .getObjectSingle(wrapper.javaClass)

OR

val wrapper = Wrapper<String>()

Rx2AndroidNetworking.post(someUrl)
        .build()
        .getObjectSingle(wrapper::class.java)

OR

val wrapper = Wrapper<String>()

val s: Class<Wrapper<String>> = wrapper.javaClass

Rx2AndroidNetworking.post(someUrl)
        .build()
        .getObjectSingle(s)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM