Parameter type must not include a type variable or wildcard: java.util.Map<java.lang.String, ? extends okhttp3.RequestBody> (parameter #1)

Android (kotlin 开发) 应用访问接口,出现如下错误:

1
2
java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.Map<java.lang.String, ? extends okhttp3.RequestBody> (parameter #1)
for method StoryService.addStory

接口:

1
2
3
@Multipart
@POST("story")
fun addStory(@PartMap params: Map<String, RequestBody>): Call<Story>

解决办法,在 RequestBody 前添加注解 @JvmSuppressWildcards

1
2
3
@Multipart
@POST("story")
fun addStory(@PartMap params: Map<String, @JvmSuppressWildcards RequestBody>): Call<Story>

参考:

https://stackoverflow.com/questions/45785874/multipart-request-with-retrofit-partmap-error-in-kotlin-android